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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B5E9D0BB60 for ; Thu, 24 Oct 2024 05:23:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A653E6B0082; Thu, 24 Oct 2024 01:23:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A156C6B0083; Thu, 24 Oct 2024 01:23:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DD346B0085; Thu, 24 Oct 2024 01:23:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6EEEA6B0082 for ; Thu, 24 Oct 2024 01:23:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3CB31AC955 for ; Thu, 24 Oct 2024 05:22:38 +0000 (UTC) X-FDA: 82707351342.09.55FA144 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf21.hostedemail.com (Postfix) with ESMTP id 3C7A41C0002 for ; Thu, 24 Oct 2024 05:22:36 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U07BvVPd; spf=pass (imf21.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729747239; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IRhqr75O4a6C4a8zm8j8sqwx+Mv66SJ15nHUK/iyHcs=; b=FySzEbnReccpUvS5GToakPvNIUr5h0Ctj33abQf1PShs8Uz5CSqj6JC+C8fTigzMnZe2+M NjCx/mLe3rXpVnhJo0D2MLpsn+cuYXIDdQrkkldvngbauSv9Aaz/6o/Pr3/5SOEQOAxcnx BywgYHKVJKlH5HhZQGIRVtN3moJYfJs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729747239; a=rsa-sha256; cv=none; b=VWAXyCKPshBTxDy+88hb96C6KUU2ywB8awCHOkVsZl2KRIt9lv79X2i3btW3ByG5kVH+G9 GeWuRVilNVmTg0TrsH0vBbGvetlspxSo9mP9tQZe4AVERxd6SwMCWniQ9QNgkkkZ1RxBp9 T9Ihp7oaZncJu/e2F2SqJbLyLEENEP4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=U07BvVPd; spf=pass (imf21.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Wed, 23 Oct 2024 22:23:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729747388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IRhqr75O4a6C4a8zm8j8sqwx+Mv66SJ15nHUK/iyHcs=; b=U07BvVPdAdAHSZAoF5VG0w7wjGc8Y5fKfZUMe6V53xnaWkpgQ7mbkowtMO/O7a5wwuwY17 lLfmtsZJ1QRE11xKc5JSAgmW/MhnQ18j2ylS1P8rd2xM+Kecwj+QWt7jfc+2bgUizwSu+7 ehN/I4f7qasr5xEFy51Jjhpul4fsHY8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Martin KaFai Lau Cc: bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Kui-Feng Lee , kernel-team@meta.com, linux-mm@kvack.org Subject: Re: [PATCH v6 bpf-next 06/12] bpf: Add uptr support in the map_value of the task local storage. Message-ID: References: <20241023234759.860539-1-martin.lau@linux.dev> <20241023234759.860539-7-martin.lau@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241023234759.860539-7-martin.lau@linux.dev> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3C7A41C0002 X-Stat-Signature: agbsbhry5cqufij5opps11pfk9k5kfmc X-HE-Tag: 1729747356-332958 X-HE-Meta: U2FsdGVkX1+rBHDd0j7OnTwQYEeSZnqsl24fhbyWTI8GQhXsseMBCW7xgBNnX5eO3JLMsU0ntHfnDqZPRraz8zxavZQjZY5kwafugwfjAJBfZ7XkrCH+QSCNjdTrwS0mlV3VdKbqdxzvAkTTpLRFV2gQMrYx9mwbVK1mx7j+1ZvsW5UDEX1oc6L4bPC/nYCBJVqN4ATpynE/6aZxwc8HcnQ8dEC10HFqKE1VfmtDPOdaF9xdof9iEzZUduS0HLjzYizgWuog49a8HkAS/GzcUuPHy+O8Nhino7dRhm2flb/TKr6x9XOeOSJIxQV97BbFZIMI7rQIOGfzItKxIMsmMNUef5rg+eZr7DZ59ZMDBPNTvz4feE/udLwS+eBopN/i1F1UJbprZO2gCnToo+5/7EUC+S+X0ZC+GGNYIFlYtanwnjP/xfk5DTN/NYbO18mQ75hzuIPpKGXuWXcufeQCZSKT6MIJe1Kawx79yIgwJLIjly/avjnRQTk6zbxb6AlgLUfX3VzrmdAAeT+FsUdGAIOZUF1Wc6HFJWtW77y0x75yb244jLhCC+Et23lPwbejNJmUWGROorGFuEk8yY5BwfDfR7LJ8p+/EUb+GHJa+dDjW6i9/dqNhE8R553NRIRhT4iqKYXFCXnJ7QvPb8+etRKHXEF3ZTQVbRi+nHnOoVtaDAe5wpuBl8fJdFL9/EvuhnLMzmJ4WqqNIky/05/O6Vy+T/HjplGoMOIj6Z5qmplKpr//7Rr4Ps9FHh0E1PwusPqkYRyXp9DpuPKWd9eApXxVjaSASNRz28XOrNQJtjulAS2z0bO6guQvxYlUB08/rndOwL+7SUvsjOJQcr71bEtY0I78bIcdVIC/R+T2/7LHpVIPI7B3DMOPa6TE+S5KFDuwdeVKPjPyCS7L++SewdbNW+cpAttAG8WmtqHJ9aL1DswtSCnWYI59lvEYid4y1lsaIgjHXJe1pmTXptQ MqjbtxVJ M1weiuvOmsDeXeyTDNZVM+4qKhxhAD/3oMxP/IUAOLpwBxeyw2lsJiZQ53ARBTp8Sj1hhBUhGNIFBLLa2QvEe4O06ihZ8Gmbc5q9PJ8y23o8Mi1ng9Kh7NKI0jqJ/ZdwVgPeM5UlyvydoSGU7lLVZCGrkcmuHLWhsKMkWPJ+2EANLb8SShOQjsxE9j6F7lBnvE8OEHcCNDSQ7adhkIZFmuFhs1T4qIRcDMhS0Dt8MnbiV8pxdwe2r51GiYXQxjJkUtFbCfp6lgN5SQpt0g4PDrtmD4kYAMuQZ1cxWZRjQw97Mp6TAidNGj06Esd2VTpZ8Tg7lo8QP4X7i7/jp1L5cjQPLqA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Oct 23, 2024 at 04:47:53PM GMT, Martin KaFai Lau wrote: > From: Martin KaFai Lau > > This patch adds uptr support in the map_value of the task local storage. > > struct map_value { > struct user_data __uptr *uptr; > }; > > struct { > __uint(type, BPF_MAP_TYPE_TASK_STORAGE); > __uint(map_flags, BPF_F_NO_PREALLOC); > __type(key, int); > __type(value, struct value_type); > } datamap SEC(".maps"); > > A new bpf_obj_pin_uptrs() is added to pin the user page and > also stores the kernel address back to the uptr for the > bpf prog to use later. It currently does not support > the uptr pointing to a user struct across two pages. > It also excludes PageHighMem support to keep it simple. > As of now, the 32bit bpf jit is missing other more crucial bpf > features. For example, many important bpf features depend on > bpf kfunc now but so far only one arch (x86-32) supports it > which was added by me as an example when kfunc was first > introduced to bpf. > > The uptr can only be stored to the task local storage by the > syscall update_elem. Meaning the uptr will not be considered > if it is provided by the bpf prog through > bpf_task_storage_get(BPF_LOCAL_STORAGE_GET_F_CREATE). > This is enforced by only calling > bpf_local_storage_update(swap_uptrs==true) in > bpf_pid_task_storage_update_elem. Everywhere else will > have swap_uptrs==false. > > This will pump down to bpf_selem_alloc(swap_uptrs==true). It is > the only case that bpf_selem_alloc() will take the uptr value when > updating the newly allocated selem. bpf_obj_swap_uptrs() is added > to swap the uptr between the SDATA(selem)->data and the user provided > map_value in "void *value". bpf_obj_swap_uptrs() makes the > SDATA(selem)->data takes the ownership of the uptr and the user space > provided map_value will have NULL in the uptr. > > The bpf_obj_unpin_uptrs() is called after map->ops->map_update_elem() > returning error. If the map->ops->map_update_elem has reached > a state that the local storage has taken the uptr ownership, > the bpf_obj_unpin_uptrs() will be a no op because the uptr > is NULL. A "__"bpf_obj_unpin_uptrs is added to make this > error path unpin easier such that it does not have to check > the map->record is NULL or not. > > BPF_F_LOCK is not supported when the map_value has uptr. > This can be revisited later if there is a use case. A similar > swap_uptrs idea can be considered. > > The final bit is to do unpin_user_page in the bpf_obj_free_fields(). > The earlier patch has ensured that the bpf_obj_free_fields() has > gone through the rcu gp when needed. > > Cc: linux-mm@kvack.org > Cc: Shakeel Butt > Signed-off-by: Martin KaFai Lau Acked-by: Shakeel Butt