From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AEAC9C48BF8 for ; Mon, 19 Feb 2024 15:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References :In-Reply-To:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+fuERE09ShTAtCe9oUokk5/14etZCe3lwEFwNIjYnjc=; b=ZmKHT8v+MP7/MK 1Mqq3RhYuB7JU3w1m5jXOvck+vWuVP8PJ2Iz0mJCLcJg4X2CSt5CEQckrldWqXGoqYZdMjunlFb/r SPxz/er0SuSXPNgfJ2I2cpTMk5TYTkhNVm8ngPtE2ZPIPqE13uFdnhGUakBJYiu5vcYV/QI/+cRaG ciDEd5Q+08MajKsIrRWkxnyT7H2z/YW/C1IoNforF0CRLXqu3GPnHok6onF66vmZqs2TMp5vXjp7C tmp2F56oZALQRmZn8IHBP50WWRww3KERwc6IDsIGgh2wMxZnZzdtyF70SBxhUOxvmRZlYS22QiHu3 ++NjkIn2ydiQHklhAvEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rc5Md-0000000B3HC-2PEH; Mon, 19 Feb 2024 15:15:27 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rc5Mb-0000000B3GA-0ZrV for linux-arm-kernel@lists.infradead.org; Mon, 19 Feb 2024 15:15:26 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4126126f4f4so11051285e9.0 for ; Mon, 19 Feb 2024 07:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708355722; x=1708960522; darn=lists.infradead.org; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :from:to:cc:subject:date:message-id:reply-to; bh=BUQoKtz44vOOVJo62FPP78n4Nrne/6aGsoTt/S82hxo=; b=dB0KBCKpCn3gsuXbTEjIabSzNryscJrW+ud/QcRUhc7HbA6CGzSMZS5yiZfDQ676uV WdYCfdWkdaz73/0EO5uM6oCm5XJ4isVQZDt3dCpLyj7ds8ZwXBLm1f3soAHXl5lhxqgX HAj+whz7/P1fi59c7n5X2pTP3qtG6i6/ZheOyFKtudCq65O5NSseH0qwixjQxqrr0HTf Zdad3li3oqSnRpGR7hmO10ModytdwLXmCQ1IS8ZU8ml/MVQrP7eIzIBWhyj1zNtTLz1Y yIm7t6LO+iJIV8qGjbPlhURh9L9tIHD9mFhKnXfzl41NTcv4LtfximM9NuSD+RKp+oGC e4Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708355722; x=1708960522; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BUQoKtz44vOOVJo62FPP78n4Nrne/6aGsoTt/S82hxo=; b=ocQVYLUkKYOck1jNNnrhUAsMzJ8+rE7z8XLGmVNAR0pc9DLa5lE4xdC+zwIxjmrjSq 34fbmV7iy3nNU5BkFIBYbDMwTRWrqqxF+KjfCPb0y8W8eFRmcE2yViZWccTvDJBbnXVN /b33mwFjfK0cRt5f+Bojl1thopM7ZPR8xj3d3nf+soD9osNEU+ePpte9aA1s4C30fF5J tzksQrOSYZyarAnMWVD831kYPZz+LKUX8/9tHdQ6AVSEVVrIkSdMNet9NU8BYM8b873S Rvn5MxxpvAIEr7LLaNVWPZNvDP7+5MyAVjkd9rkSB/q3WhFfMZ09m6pwxE1WlAGW2bq1 1EKA== X-Forwarded-Encrypted: i=1; AJvYcCU9RdDv2C/MRkMjiRrqA7lM55UJ0faWFIJzvVwKTy6t/h7eY1qirdrQ3dwy4kEiM+Cr+6DkR2Uk+hvMmCl9SSgBe7S8XC6zp9zMKP7kwFzVeZr4TYo= X-Gm-Message-State: AOJu0Yy8Vai0ROGQueHTkAwIWCqj8pyCBW5oe4R/AaSKMnWMLwZWBdnF znTS2kK8vCzhHmlflKxVYj1VOiKNOxJGjeCfiJknNOVW+tdSCd9f X-Google-Smtp-Source: AGHT+IFNc2bddpDmHF5WMNwyiQh2ePqca0WdGeTGxcJa8okEtUtxcrk9VhcgJd0YK5ODCJ7PA6yzxQ== X-Received: by 2002:a05:600c:1f8d:b0:410:c5a9:a24a with SMTP id je13-20020a05600c1f8d00b00410c5a9a24amr9785269wmb.20.1708355722344; Mon, 19 Feb 2024 07:15:22 -0800 (PST) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id l5-20020a05600c4f0500b0041253692606sm9913320wmq.17.2024.02.19.07.15.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2024 07:15:21 -0800 (PST) From: Puranjay Mohan To: Xu Kuohai , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, bpf@vger.kernel.org, kpsingh@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH bpf-next v7 1/2] arm64: patching: implement text_poke API In-Reply-To: <79088869-a5ba-4335-b3ab-8a2a26d8be74@huaweicloud.com> References: <20240125133159.85086-1-puranjay12@gmail.com> <20240125133159.85086-2-puranjay12@gmail.com> <79088869-a5ba-4335-b3ab-8a2a26d8be74@huaweicloud.com> Date: Mon, 19 Feb 2024 15:15:20 +0000 Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240219_071525_201566_8CC0BD00 X-CRM114-Status: GOOD ( 22.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Xu Kuohai writes: > On 1/25/2024 9:31 PM, Puranjay Mohan wrote: >> The text_poke API is used to implement functions like memcpy() and >> memset() for instruction memory (RO+X). The implementation is similar to >> the x86 version. >> >> This will be used by the BPF JIT to write and modify BPF programs. There >> could be more users of this in the future. >> >> Signed-off-by: Puranjay Mohan >> --- >> arch/arm64/include/asm/patching.h | 2 + >> arch/arm64/kernel/patching.c | 80 +++++++++++++++++++++++++++++++ >> 2 files changed, 82 insertions(+) >> >> diff --git a/arch/arm64/include/asm/patching.h b/arch/arm64/include/asm/patching.h >> index 68908b82b168..587bdb91ab7a 100644 >> --- a/arch/arm64/include/asm/patching.h >> +++ b/arch/arm64/include/asm/patching.h >> @@ -8,6 +8,8 @@ int aarch64_insn_read(void *addr, u32 *insnp); >> int aarch64_insn_write(void *addr, u32 insn); >> >> int aarch64_insn_write_literal_u64(void *addr, u64 val); >> +void *aarch64_insn_set(void *dst, u32 insn, size_t len); >> +void *aarch64_insn_copy(void *dst, void *src, size_t len); >> >> int aarch64_insn_patch_text_nosync(void *addr, u32 insn); >> int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt); >> diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c >> index b4835f6d594b..5c2d34d890cf 100644 >> --- a/arch/arm64/kernel/patching.c >> +++ b/arch/arm64/kernel/patching.c >> @@ -105,6 +105,86 @@ noinstr int aarch64_insn_write_literal_u64(void *addr, u64 val) >> return ret; >> } >> >> +typedef void text_poke_f(void *dst, void *src, size_t patched, size_t len); >> + > > How about removing the argument 'patched' and passing 'src + patched' as the > second argument? > The memcpy() function needs 'src + patched' but the memset() needs only the 'src' and will ignore the 'patched'. To make these implementations generic, I pass both src and patched separately and allow the implementation of text_poke_f() to use them. If you think there is a better way to implement this then I would love to use that. >> +static void *__text_poke(text_poke_f func, void *addr, void *src, size_t len) >> +{ >> + unsigned long flags; >> + size_t patched = 0; >> + size_t size; >> + void *waddr; >> + void *ptr; >> + int ret; >> + >> + raw_spin_lock_irqsave(&patch_lock, flags); >> + >> + while (patched < len) { >> + ptr = addr + patched; >> + size = min_t(size_t, PAGE_SIZE - offset_in_page(ptr), >> + len - patched); >> + >> + waddr = patch_map(ptr, FIX_TEXT_POKE0); >> + func(waddr, src, patched, size); >> + patch_unmap(FIX_TEXT_POKE0); >> + >> + if (ret < 0) { > > Where is 'ret' assigned? > Will remove the error check in next version as func() is of type void and this error check was left from the previous version. Thanks, Puranjay _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel