Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1195754rdb; Mon, 19 Feb 2024 07:15:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUazlzTBtbbMNZTeR8YCkzNfWPDjnq4TvzzysiX9LcA/NSsx8VJDnCklnd/+bZOL5CyKHzgT46ek1sF+aTndAYQziS5QByc8w0eq04cNw== X-Google-Smtp-Source: AGHT+IEPcixWpeBnITBru4Viz8chbC94To7AN+8+bGwPfNSzwOT+TbzUdtLuA5q6hRfCxH9bkoGY X-Received: by 2002:aa7:d3c6:0:b0:563:cc31:44c5 with SMTP id o6-20020aa7d3c6000000b00563cc3144c5mr8354886edr.2.1708355737661; Mon, 19 Feb 2024 07:15:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708355737; cv=pass; d=google.com; s=arc-20160816; b=CtIhfu+xg0C1PRXTAT1EYyILZ67e3aIJd3ODDlBmG6i8UXa7kit8WQkLNLHoimYKYs XPk4SO+F9hEsqqtdXZu9HLueTx9XSKkfarCpJtk4lpWRK6tgW8Nd23lmL/Yz9/0K7KMF bIgo55I8RcH7NTh2XM9/8hOmmxOG1hPf6CBot058R3WQv84yhKp13+piwlUy8MRT8Bto saGV+is1Snc9+kq1dCDYllDc4z8l+z6y7vMrPOM0/EXk6qwIQvg2FtOvI1pNhmgvTpfW rNp4ebYao9SAHO6qJVJylyBLdz6oRPiGJ2MSZP7RWhdfxhCTCE3LKywx7lZffEWttiAY iG2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:to:from :dkim-signature; bh=BUQoKtz44vOOVJo62FPP78n4Nrne/6aGsoTt/S82hxo=; fh=z6cDiaAJno4izqO7InxNgspgVrqasN7h75AignZzyi8=; b=HIn5mGhjf2xtbAEmW80pV77ZPR9qAeaIud8DwBYKG5A84DGgPoxpP1+U/LfPHZMIcJ 5YWOSMn/t4nf9KRMhu+tPucIniq0I/6zaBBKMXsKmPPBfofxjEz8S5kEfSKHlMHiErDT HfKkQEEnxGV8MptfMGgZP58+D77XtrmFrDerF+LWvatmD3SXZ3pC2abLPCPNYsafFhEv jZ6/E8K8qMoItIuz79BROQbXh95eTE7sWcI0FVb3AZiFtw2YD0Yq0HsE15KZ1ElVDmj4 ViRQHPTO5QXFN0jKltAhbaMQeQarCcglPMO/6wKHN0XtA4GN49qE/chGzloHiYJOQhdE Bteg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZmsOnAFN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ch1-20020a0564021bc100b00563d32f42c0si2562081edb.555.2024.02.19.07.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 07:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZmsOnAFN; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-71568-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 447C11F224F1 for ; Mon, 19 Feb 2024 15:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81B113839B; Mon, 19 Feb 2024 15:15:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZmsOnAFN" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E39D38384; Mon, 19 Feb 2024 15:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708355725; cv=none; b=Avk2ZMX+Ahxj49vTtx+QxmOiWIdsB4uBJlug2mKzDfE8ad4oAqUHA6uTir1Z3zSmYjLiSDgz4Za9LQ2obKneMIAyZf0GIO0xg/QE5x5j0vvtAJGX39EBJuxdiHIAXvyqmFuHFlDzOZS1+Uwoh0t1rq0Td7QFWLc/J/bmRvMg/Do= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708355725; c=relaxed/simple; bh=aJvikAeIgXMvlPz4lvrIgTsZaCV2Z527m3bSofD38vE=; h=From:To:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=kTccW26TkvConYW+wSZAj2bMmquzJjuRBH78fSXHnyFDYBtuTZfUCBnRHGU8vGprE7IQvUz9YN5g6qw4wU0U6fvgtJC+LNPNNyMUJrN8m+0Lr2Lp+5Ws5Ep893CHIEcUEAwEVLK2JCX4J6pBcwNFSkLj6TZwVWvunHlxqReDy/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZmsOnAFN; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41265e39b8bso7574835e9.2; 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=vger.kernel.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=ZmsOnAFNA+cxlZwxoSdCAFtFsslm8HpQQE6kZVmbCo5HGVDt4diJbInBNwW65DqHi1 oiYI9SNvMC99yVoIp0VJ/AaB++Z9Blr9jDi6zE+OGvkB20YVvjB1GBbKapmQzivGhLqa PnD3pxE8nLcwQJQBZIuUMGlsAU64v7ElkiZnTTmzCMHGDhuiBpNNTX6pYnzcgL+cW5DI W/KEpZm42lQiWUFKhGar3etw7LhN1jjJbfFCI0hKmeFb9Usq/5o8Zj4jleIDN6MBAJj6 ZvhwEZeY7M1OZELUH5Bl+3WXa++tStZX+yvcXqPb50/F+Agm4p5yf03W9Uk7QiPAUNux oPDg== 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=J5gYjzPU0GYCpVYmuHrIZr8/9gB77aGHRjnC27Y46zMEwAIJDEAKg5ZJ9Uy0JNqd4s 6/ZaQjG0shd1DhMg7JNwGBb5NZ4iHcWjakwPrIqIpxYQZayl2rCPIAtgIsiuib1H4sju +XrGIdF3EVtCQtB9ihxMQkk9tnjc+3zMAJpKtUx58skFpcsZHhnd7fa4gak87mV2OhJU M0mWm6B8f5G8MdJJBOpXexJB009A8ODKBNZ0eZZ79gGa4XpX33t1GNdzdW+M+J+uBnZq duKIDjFaZnwE2zDeCWgS3GBcdWVGf5PTq4zXnFqd0293Mzsj3OE8ZbDGaY8/+fpiP9Yj 0Row== X-Forwarded-Encrypted: i=1; AJvYcCVSYqjX8RFE049Y9gTFeXJNG3G/ywU2FKP4e3Vi9CbaQ19QcEuiXDCgLwQgqVjG6DNJGObj73I8R1Bf1BctXvnkDIKJ2AdrTeauaZNLUzAJokgZ/wIIiSpdNOAyR7jNuQHn X-Gm-Message-State: AOJu0Yxxu887jHPnipkCpouttWhoKwuNF5bU7WTGbkfPkRlodA2g6ANQ zbVZU2uOq85SgvnAw5YKOQxjtGvX/5DgASbTv2A9E1JiX+d1S9f0 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain 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