From patchwork Fri Feb 23 23:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13570153 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 3C1DDC5478C for ; Fri, 23 Feb 2024 23:57:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9F056B007D; Fri, 23 Feb 2024 18:57:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C26B96B007E; Fri, 23 Feb 2024 18:57:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1726B0080; Fri, 23 Feb 2024 18:57:39 -0500 (EST) 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 956226B007D for ; Fri, 23 Feb 2024 18:57:39 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 603F412124C for ; Fri, 23 Feb 2024 23:57:39 +0000 (UTC) X-FDA: 81824733438.12.E71DFE4 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf23.hostedemail.com (Postfix) with ESMTP id A61CB140008 for ; Fri, 23 Feb 2024 23:57:37 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIjIDhNc; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708732657; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=P8IvlQlz3dHl0wg/LhztCmdAmJ77x9s8BT6z4EVCeZfxcmIHFdZyTmoWqcWlTWb42mD85Q vg8gov27pHX1OGvxEOEPAtGL4qk0vEFsSxoNudLoVulHQMSsGJrwd/iIdVuGw8obVvnlea 1mncznrVov6wN2g+4bFS6gY30hlRAdw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIjIDhNc; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708732657; a=rsa-sha256; cv=none; b=5jHOwAAaOJHueUBTceRu+zlHQSjaoyqqnILYzpe4ANq5NLUJ7LXycz5Fv0S9mAMPFCXGgv 164OWZ2ysa+iU+rGBM69zN3imjPhyux9qgGOtrI9hyH6h5NRYjUd1aOcxPD8SZqthH39TR G+h9UCQhYly2aZ1z+cKwG/TE9k6TUcw= Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-29a74c88f74so910955a91.3 for ; Fri, 23 Feb 2024 15:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708732656; x=1709337456; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=iIjIDhNckyj0w78CuclqmockKfw21I2IrZBh+2h7JjeXDrEfvuZqjl8z4vLATUP2gB K58DiMytyu5XEWLDTfr5tHO7W/byJNeoZYqIRxtHU7RibQ782cTCfeWSVXn+4QthSOTx WBMGKaDuTpVc/cbqgUWHSy4p8pA2m6g/u89CVMahL8yiWxyk+iCZb+RknxSxfxioz2vj ZFDbAVPOAw+vXBUJOJgDT0kC3YBiIsCjAr+1hLfGFeYXaPzfCPcwjSfBrpOFM5VHZjBO KjviioDG4ttQDrEZQM+tiwCryYhBbVJnIvvGVfJea9ZNK/J346H0q5rm5yc1sZ2rlehn bE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708732656; x=1709337456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A7v8QcQGKEfLwaJltNJW0mYz5w9KdmkVXr/8REE7aG4=; b=B3rScWde+WCHFcBD8l6Y32paA6RJo96IVIkLxHNOZ8tX6DCueIrNdxBkTW3M+gylb2 lPDI3ICzr7xwRfGhOCZvtcXBZftRHkGo8Ua6aohhrqFNQPhZSMhIZ2xWmB/EWlPYt90z lyJpYMuy7Pe8UmJ9j9idMdyrsdW4RBZIX2LcPX2o9YGNrdswTC3N0GSR9GNKW77U4e6F G/b8gD72s2ABOklwPgmjtHX+biTqczr57Lu3neM4T769HejavC5mJO0M7tyb5849JEgX DQMXp/vftdn2kbagPsj1PQeNmgdtnQOsqWrYxsFQICvdo3eFGeyFni2z0mL8ZIQk+ETi YxEg== X-Forwarded-Encrypted: i=1; AJvYcCUahZWDM4nyREXb6D8Xftv6uhDPXJSNUqAbwnlxPFNL+O40ZeDPZ64ypS2FFUbqkUAfR4YVYXvaSuOWtlwXguuuu5A= X-Gm-Message-State: AOJu0Yy2mmNPr6LamhzMO/gLhhaeZ6Lf9YGfmwUIGzOBoMbYh71sMeZv 7QHdf4yRCwhWSHgY77gYSuNUlNS5bhH1xAfXoe/GM6Sq0fjQLw8o X-Google-Smtp-Source: AGHT+IHG/DO/OVIktjtp11/4CHtLMBPBSMQzb2KGZX31cgPqxxDf+7H9BLoJUXmr0UjElOG7XOtMJQ== X-Received: by 2002:a17:90b:1050:b0:29a:9ba0:8a5b with SMTP id gq16-20020a17090b105000b0029a9ba08a5bmr411918pjb.5.1708732656476; Fri, 23 Feb 2024 15:57:36 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::4:45de]) by smtp.gmail.com with ESMTPSA id si4-20020a17090b528400b002963cab9e2asm2161658pjb.2.2024.02.23.15.57.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Feb 2024 15:57:36 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, boris.ostrovsky@oracle.com, sstabellini@kernel.org, jgross@suse.com, linux-mm@kvack.org, xen-devel@lists.xenproject.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 1/3] mm: Enforce VM_IOREMAP flag and range in ioremap_page_range. Date: Fri, 23 Feb 2024 15:57:26 -0800 Message-Id: <20240223235728.13981-2-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240223235728.13981-1-alexei.starovoitov@gmail.com> References: <20240223235728.13981-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A61CB140008 X-Rspam-User: X-Stat-Signature: du13r7enbdxngayhptmc3dkbi448iad6 X-Rspamd-Server: rspam01 X-HE-Tag: 1708732657-53238 X-HE-Meta: U2FsdGVkX1+dr+LwEwc5dWzXSiwJtluV9/0mbfeTGz/bDHe/iAWbD5cEqzWy3fu7VkQJhHbfqLnYTm02AT7BTaXRCUNgFQ6iA/h9865SmOfY05eD8A73YIDDN2qyMGRdYp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version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov There are various users of get_vm_area() + ioremap_page_range() APIs. Enforce that get_vm_area() was requested as VM_IOREMAP type and range passed to ioremap_page_range() matches created vm_area to avoid accidentally ioremap-ing into wrong address range. Signed-off-by: Alexei Starovoitov Reviewed-by: Christoph Hellwig --- mm/vmalloc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..f42f98a127d5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -307,8 +307,21 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end, int ioremap_page_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { + struct vm_struct *area; int err; + area = find_vm_area((void *)addr); + if (!area || !(area->flags & VM_IOREMAP)) { + WARN_ONCE(1, "vm_area at addr %lx is not marked as VM_IOREMAP\n", addr); + return -EINVAL; + } + if (addr != (unsigned long)area->addr || + (void *)end != area->addr + get_vm_area_size(area)) { + WARN_ONCE(1, "ioremap request [%lx,%lx) doesn't match vm_area [%lx, %lx)\n", + addr, end, (long)area->addr, + (long)area->addr + get_vm_area_size(area)); + return -ERANGE; + } err = vmap_range_noflush(addr, end, phys_addr, pgprot_nx(prot), ioremap_max_page_shift); flush_cache_vmap(addr, end); From patchwork Fri Feb 23 23:57:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13570154 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 54B45C54798 for ; Fri, 23 Feb 2024 23:57:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D641F6B0080; Fri, 23 Feb 2024 18:57:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D11B76B0081; Fri, 23 Feb 2024 18:57:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B64E76B0082; Fri, 23 Feb 2024 18:57:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9CAA26B0080 for ; Fri, 23 Feb 2024 18:57:43 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4D910A189F for ; Fri, 23 Feb 2024 23:57:43 +0000 (UTC) X-FDA: 81824733606.21.16708CB Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf17.hostedemail.com (Postfix) with ESMTP id 778154000C for ; Fri, 23 Feb 2024 23:57:41 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CEVqy5W4; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708732661; a=rsa-sha256; cv=none; b=5ez/WC7peRUXwjN1P34A5VSOh1+8DGsaPWLGhAX3TRghGSslRongYO0d9l3LJ0Phtv3vVS ZHajO+tsU3A1DtccL+T/Db8L8Oo7fjapmpepF8HV0Lj07dtqPpueD1fN11jLCJd6W8fmhV 2DNXkQNTjC5ZzAQHvosSEJcCx80Vyh0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CEVqy5W4; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708732661; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wgy7UuZvicma9Y2PX48aaJ5ZDCArBODZAL7mSlN3pk0=; b=VxKykIz2IDDyC/jgqyb+868NySvN394a7Cilfooqr3TRwl96xmq4aHBhLd+fBlGxB01Wi3 pBuqr/kay3SaWXVAZjkBK5PtVPeccDtwDjihTAngzKksLqhtAut1RggZUD/Rlle/WvRDtg mlOilw5Squ82ZbfrFsDfNHl1qsHcyy8= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1dba177c596so9945825ad.0 for ; Fri, 23 Feb 2024 15:57:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708732660; x=1709337460; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wgy7UuZvicma9Y2PX48aaJ5ZDCArBODZAL7mSlN3pk0=; b=CEVqy5W435RfHUtYxOCib6ENbSu9SGCVqm9+UafHQCz9lPDx0M5gqUexFsKoaydNAC NBJ+PV6IBZsaG3ckOx11SZ3sr205u2I5LDYFe63itnglWqWZMuprgWo8yGo1d7qsYvk8 8lzUwhqzjSIgL1XmcG6Q74fJooAC43djtIXKhTrpljWfdYu+6R0aiw1xxozHYsI0Gx+G FQaxfVH1ZW+zWBlbjvST0Agmc0KlzK2aLPpyStkw4knKtE4+jy2vF0JUdICF+2NvvWGd PM9ImIM+tSrbIrnLy5jhBFGDPUKGy+Vgf6HfE/KqOgnB7tR40RK/eVf0B61hx6em0jl+ ZIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708732660; x=1709337460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wgy7UuZvicma9Y2PX48aaJ5ZDCArBODZAL7mSlN3pk0=; b=gP7IXwHRgHZzxnylOx7/6HyghgoC0pT0zS56C7ZBatVoieAuJ950u9jvHXNEY75EIj gcnSWRLAdRkVugGTls1o9AtBGV+bOSWZGoJ2SxarrRM3VJC97aQIrF9Tu47JdgXP/Fir EpCI3KwInf1uV6+g/71wpc8IYTGv843uvwPoLzyfVINjVv383AP6vLAe990/t3jdZ8Ox D7Cxq3e8wx574JqNxIWPJK4ak1vdy0qYf/LFK2ueciFfaTlG0m/NILfRyj6dl+Ri4CNo pB3Rp6hANTQ2CG3Om1KtUDxGDrRVUB3WzaWZWrZmVQm7d4gkyfOuNXgZENKmC0rE3o/Q hDBA== X-Forwarded-Encrypted: i=1; AJvYcCXXx7MuiOKjCVDW3jTtrB3rZ2Ij3iXQfiFBlExcG9Au+TMwpeW1sjg1qqe/7iaBOP3Kvei4IqA4gxv4qdnwpBdvZ+M= X-Gm-Message-State: AOJu0Yzjc/U10C9uGVhnAutqT0nF33unzE1ndcpdfx1j2ANPEPA9B67T shZV5kSD9wXsolIZeQVCtQwjBdKxYZ4kNhwzkOCiaGsGG251A6aR X-Google-Smtp-Source: AGHT+IGELhXnvr3n524zH97gDxBoJwFKXzefQUh+8dOBuQvkiJz95RKjpkB2JqjALLNdOQ3Mm4DyFA== X-Received: by 2002:a17:902:f645:b0:1dc:b64:13cd with SMTP id m5-20020a170902f64500b001dc0b6413cdmr1551144plg.27.1708732660213; Fri, 23 Feb 2024 15:57:40 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::4:45de]) by smtp.gmail.com with ESMTPSA id bc7-20020a170902930700b001dc486f0cb2sm3796745plb.208.2024.02.23.15.57.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Feb 2024 15:57:39 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, boris.ostrovsky@oracle.com, sstabellini@kernel.org, jgross@suse.com, linux-mm@kvack.org, xen-devel@lists.xenproject.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 2/3] mm, xen: Separate xen use cases from ioremap. Date: Fri, 23 Feb 2024 15:57:27 -0800 Message-Id: <20240223235728.13981-3-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240223235728.13981-1-alexei.starovoitov@gmail.com> References: <20240223235728.13981-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 778154000C X-Stat-Signature: yhj1de9kehwmq185x7p9j3gn549m6re7 X-Rspam-User: X-HE-Tag: 1708732661-547004 X-HE-Meta: U2FsdGVkX18QrBVzs666LAFBN1kHfIHdKYDKjBkn2RF9y00t05DWVWoknKPRiImAFaZOiUXmv52KjQBgn68vUYNX2uv67vtYAc4Z27X9iOb3K978ZWCszKuy8Yf4tVZPvQgT/g9XsEJwFHnpBAqt2IzkbTeEgr9XLx1Wy6PTOgF8PKY8LVA17ipavrxIh/PnJm+YISMVclZGQ5qIwlwDe58tYGHLK3ZZ1ssv506fQbzTuNqlACuOP8vFiawOfX8g9mFjaRnFMNLvle2jeQhtbXWX8POqH0ON9oXBROX5+E4KKZhm3gU26ObTWMzwaU1MvMRkKZ687skd1mvpOyvOnL2+FYURst2ueuml1Vykbmf3Fa/zlApFLg7yTWu2nXbhDlOfVQASU9pOSu1C71gV7YZZ/csH22SW60JfEWJGCJzNG20MkuJBir6lAHsqp2o+75qa5CAFqIbkG132Ze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xKFEfsVHid5g== 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: From: Alexei Starovoitov xen grant table and xenbus ring are not ioremap the way arch specific code is using it, so let's add VM_XEN flag to separate them from VM_IOREMAP users. xen will not and should not be calling ioremap_page_range() on that range. /proc/vmallocinfo will print such region as "xen" instead of "ioremap" as well. Signed-off-by: Alexei Starovoitov --- arch/x86/xen/grant-table.c | 2 +- drivers/xen/xenbus/xenbus_client.c | 2 +- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 7 +++++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/xen/grant-table.c b/arch/x86/xen/grant-table.c index 1e681bf62561..b816db0349c4 100644 --- a/arch/x86/xen/grant-table.c +++ b/arch/x86/xen/grant-table.c @@ -104,7 +104,7 @@ static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames) area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL); if (area->ptes == NULL) return -ENOMEM; - area->area = get_vm_area(PAGE_SIZE * nr_frames, VM_IOREMAP); + area->area = get_vm_area(PAGE_SIZE * nr_frames, VM_XEN); if (!area->area) goto out_free_ptes; if (apply_to_page_range(&init_mm, (unsigned long)area->area->addr, diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c index 32835b4b9bc5..b9c81a2d578b 100644 --- a/drivers/xen/xenbus/xenbus_client.c +++ b/drivers/xen/xenbus/xenbus_client.c @@ -758,7 +758,7 @@ static int xenbus_map_ring_pv(struct xenbus_device *dev, bool leaked = false; int err = -ENOMEM; - area = get_vm_area(XEN_PAGE_SIZE * nr_grefs, VM_IOREMAP); + area = get_vm_area(XEN_PAGE_SIZE * nr_grefs, VM_XEN); if (!area) return -ENOMEM; if (apply_to_page_range(&init_mm, (unsigned long)area->addr, diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index c720be70c8dd..223e51c243bc 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -28,6 +28,7 @@ struct iov_iter; /* in uio.h */ #define VM_FLUSH_RESET_PERMS 0x00000100 /* reset direct map and flush TLB on unmap, can't be freed in atomic context */ #define VM_MAP_PUT_PAGES 0x00000200 /* put pages and free array in vfree */ #define VM_ALLOW_HUGE_VMAP 0x00000400 /* Allow for huge pages on archs with HAVE_ARCH_HUGE_VMALLOC */ +#define VM_XEN 0x00000800 /* xen use cases */ #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ !defined(CONFIG_KASAN_VMALLOC) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index f42f98a127d5..d769a65bddad 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3822,9 +3822,9 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count) if (flags & VMAP_RAM) copied = vmap_ram_vread_iter(iter, addr, n, flags); - else if (!(vm && (vm->flags & VM_IOREMAP))) + else if (!(vm && (vm->flags & (VM_IOREMAP | VM_XEN)))) copied = aligned_vread_iter(iter, addr, n); - else /* IOREMAP area is treated as memory hole */ + else /* IOREMAP|XEN area is treated as memory hole */ copied = zero_iter(iter, n); addr += copied; @@ -4415,6 +4415,9 @@ static int s_show(struct seq_file *m, void *p) if (v->flags & VM_IOREMAP) seq_puts(m, " ioremap"); + if (v->flags & VM_XEN) + seq_puts(m, " xen"); + if (v->flags & VM_ALLOC) seq_puts(m, " vmalloc"); From patchwork Fri Feb 23 23:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13570155 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 17B32C54798 for ; Fri, 23 Feb 2024 23:57:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 991246B0082; Fri, 23 Feb 2024 18:57:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 941516B0083; Fri, 23 Feb 2024 18:57:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 795366B0085; Fri, 23 Feb 2024 18:57:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 640806B0082 for ; Fri, 23 Feb 2024 18:57:47 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3CDCC1A108B for ; Fri, 23 Feb 2024 23:57:47 +0000 (UTC) X-FDA: 81824733774.25.28AEBA2 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf08.hostedemail.com (Postfix) with ESMTP id 64893160005 for ; Fri, 23 Feb 2024 23:57:45 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Fb4t3/FU"; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708732665; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4T/JxyeGclar7cIIHLQMvHUD6oGOKffCuXl9nke3dJg=; b=vpOrRLRRhzgQkiBCBvMFPlK9dxj2rC3kmBVC5o5xk1khaTmPpj6W8CKoJeuM6aqfNi0KBB 2m/tMNTisS14eZTn7jBR9Rcta7wfL0ng3H7pMXQfQDqR7Q4kKvtlNjRhcXAr8P2qaffJXO OfdOWArcdqDL3KLv8Eboe+A7CfS2Ytw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Fb4t3/FU"; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708732665; a=rsa-sha256; cv=none; b=OasISChAjJJfdTh0xqqo2Y9QsowspFODZtWiu4uW0Mu5GPMBrbfBYRv7K9R8Yi3ToWyTOx vp2ErHjbAvro59T2AyhkF1ce2MT6/Hrmu0lvjwt79/Hplc50WH0XrK3TRyeKiYq5kZlRFU Zc05Chzz6wdHbIWLqJo4HxUgOkjCl3I= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dbd32cff0bso7456165ad.0 for ; Fri, 23 Feb 2024 15:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708732664; x=1709337464; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4T/JxyeGclar7cIIHLQMvHUD6oGOKffCuXl9nke3dJg=; b=Fb4t3/FU5y25AX9sI8W2zLZrvJ2xzNSyOIMEBkjisQA8eF/J1/5Um2CXGP5GdUn4mi Vvvf5EmvvMolx9Lsyi1/NOvhm249aZzE73CwZRVZH9WyHoYkc7qpE+0JWUUes8yWBL2D gsPyQil3hsLNPluCPxtvQj9YvDGvKUxqmnQrgAV9y9MpecwrbKP+mPQmRMfcdGNJtIq+ P+sEvEPXQOcqODsMX6g3mHO1Aj0flEI75YpsmfyA1xwV1qKgKr/uY01NBBaU2x056AJV vzSG1/bcBrjuFOcq+OsHrJUgg+atOw2OvU9xxIGt6WZxubG/NqtWXjr8qYn9gpBpOHK+ 1YRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708732664; x=1709337464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4T/JxyeGclar7cIIHLQMvHUD6oGOKffCuXl9nke3dJg=; b=j842n3WNhXrPLgxhYHbS9Sx19d/mu9WtQlXxS20G+zrdmiu8o4X70DZs4hLc6HhJ7f g/SnZEp5g6dsr7O7lPGtc0VBb80xZPorzr9hOcrH+oHAbG4qDThoC4ul5eBGJBbK8VlT JE08S+sx8TkC/vE/iW80dWpaP3i0tiRc/Zk4iNM/QnCfUWrIUimoTGKTzaeEChXno0BF ufnZcoCpv4FbwvMPpv3fEHyXdq7gnj9NzVf2/4GsPkzefiE5cK6Aal02y0nmQaoXhP3z GeLKKVjK+z/TRvrV8xnMMeEIU/kQcdKBd90Sb90sAhwdYus+L4tEO7bRn5+zr7eSx1bS nzdA== X-Forwarded-Encrypted: i=1; AJvYcCVS9UnG8m+rgpoQMYBpG4zLvxHaVt++LIZ7yIOVHnroej5xzRetklrWio/FT8nOcgsdc2XzBVKLOysAcgIz8CCSTKQ= X-Gm-Message-State: AOJu0YwskyPKbofRUb4Od4OpjOJfRKAmKomeJpIfU67tJNOI/7FBu3cP N8V5vs8sylukDeCrqDjsXoNhWf7UvtPm2/QfYmOYplzEanqpZQ4H X-Google-Smtp-Source: AGHT+IGrC0E10ADJh+Q28iXnJRIwpr5YwuUUqZaBfkmopbBhR99u1mcgLWatOYemqm7CQuFVwzUw8A== X-Received: by 2002:a17:902:c40d:b0:1d9:d341:b150 with SMTP id k13-20020a170902c40d00b001d9d341b150mr1582992plk.40.1708732664121; Fri, 23 Feb 2024 15:57:44 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::4:45de]) by smtp.gmail.com with ESMTPSA id d11-20020a170902728b00b001dc23e877c1sm6175189pll.265.2024.02.23.15.57.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Feb 2024 15:57:43 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, boris.ostrovsky@oracle.com, sstabellini@kernel.org, jgross@suse.com, linux-mm@kvack.org, xen-devel@lists.xenproject.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 3/3] mm: Introduce VM_SPARSE kind and vm_area_[un]map_pages(). Date: Fri, 23 Feb 2024 15:57:28 -0800 Message-Id: <20240223235728.13981-4-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240223235728.13981-1-alexei.starovoitov@gmail.com> References: <20240223235728.13981-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 64893160005 X-Rspam-User: X-Stat-Signature: 947stxng4guho8fi9s6ue1e676w9u1ic X-Rspamd-Server: rspam01 X-HE-Tag: 1708732665-364946 X-HE-Meta: U2FsdGVkX1+cWQfuS0nuAQPT/bFvMjfqZEwtbULG3sZ08VlOv8D/W96Dlz0a48/cbkSlhKLyOlhjp6K1y+PcH4Jg0FuoXsVLrkSmLuwNltaaDGdOJHLbvrlTvdmF3Zi/k2eBw3o5KgYw5GamB9yHHmBecoKN6TyqZ6f92NE8gXCDobwq0mctNyz4ywDi9JAtdxYaHv7eGjQ6BTTd3R8iWrtpOIIC/0JFZUFdHyCo0EH+Nv3tX/5xijGKUM6aFUrvXLnxDwE0DiQ3y8kK5Bf80Re3pIwn63ApBFedB9czU9pcspelnMCWPbpEGwWwl7g+Vpk4Sb6kDDWbYH+P5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Xs4QOULzT5Kv+vu4hNQccg8DcUEukOdCFdVNPifLA1rVVgU68pVFFUW/yWovUnDJIc8QHiKR31Bi2eVHXC109F1H5GJdbNK7jjuziSx2h48YqfnI+N/LHIrWxObyj/s4AV8LRRwOyj5Ns0oK5iMSKYrFgRvs/LIunM+J6WtAyizpN 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: From: Alexei Starovoitov vmap/vmalloc APIs are used to map a set of pages into contiguous kernel virtual space. get_vm_area() with appropriate flag is used to request an area of kernel address range. It'se used for vmalloc, vmap, ioremap, xen use cases. - vmalloc use case dominates the usage. Such vm areas have VM_ALLOC flag. - the areas created by vmap() function should be tagged with VM_MAP. - ioremap areas are tagged with VM_IOREMAP. - xen use cases are VM_XEN. BPF would like to extend the vmap API to implement a lazily-populated sparse, yet contiguous kernel virtual space. Introduce VM_SPARSE vm_area flag and vm_area_map_pages(area, start_addr, count, pages) API to map a set of pages within a given area. It has the same sanity checks as vmap() does. It also checks that get_vm_area() was created with VM_SPARSE flag which identifies such areas in /proc/vmallocinfo and returns zero pages on read through /proc/kcore. The next commits will introduce bpf_arena which is a sparsely populated shared memory region between bpf program and user space process. It will map privately-managed pages into a sparse vm area with the following steps: area = get_vm_area(area_size, VM_SPARSE); // at bpf prog verification time vm_area_map_pages(area, kaddr, 1, page); // on demand // it will return an error if kaddr is out of range vm_area_unmap_pages(area, kaddr, 1); free_vm_area(area); // after bpf prog is unloaded Signed-off-by: Alexei Starovoitov --- include/linux/vmalloc.h | 4 +++ mm/vmalloc.c | 55 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 223e51c243bc..416bc7b0b4db 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -29,6 +29,7 @@ struct iov_iter; /* in uio.h */ #define VM_MAP_PUT_PAGES 0x00000200 /* put pages and free array in vfree */ #define VM_ALLOW_HUGE_VMAP 0x00000400 /* Allow for huge pages on archs with HAVE_ARCH_HUGE_VMALLOC */ #define VM_XEN 0x00000800 /* xen use cases */ +#define VM_SPARSE 0x00001000 /* sparse vm_area. not all pages are present. */ #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ !defined(CONFIG_KASAN_VMALLOC) @@ -233,6 +234,9 @@ static inline bool is_vm_area_hugepages(const void *addr) } #ifdef CONFIG_MMU +int vm_area_map_pages(struct vm_struct *area, unsigned long addr, unsigned int count, + struct page **pages); +int vm_area_unmap_pages(struct vm_struct *area, unsigned long addr, unsigned int count); void vunmap_range(unsigned long addr, unsigned long end); static inline void set_vm_flush_reset_perms(void *addr) { diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d769a65bddad..a05dfbbacb78 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -648,6 +648,54 @@ static int vmap_pages_range(unsigned long addr, unsigned long end, return err; } +/** + * vm_area_map_pages - map pages inside given vm_area + * @area: vm_area + * @addr: start address inside vm_area + * @count: number of pages + * @pages: pages to map (always PAGE_SIZE pages) + */ +int vm_area_map_pages(struct vm_struct *area, unsigned long addr, unsigned int count, + struct page **pages) +{ + unsigned long size = ((unsigned long)count) * PAGE_SIZE; + unsigned long end = addr + size; + + might_sleep(); + if (WARN_ON_ONCE(area->flags & VM_FLUSH_RESET_PERMS)) + return -EINVAL; + if (WARN_ON_ONCE(area->flags & VM_NO_GUARD)) + return -EINVAL; + if (WARN_ON_ONCE(!(area->flags & VM_SPARSE))) + return -EINVAL; + if (count > totalram_pages()) + return -E2BIG; + if (addr < (unsigned long)area->addr || (void *)end > area->addr + area->size) + return -ERANGE; + + return vmap_pages_range(addr, end, PAGE_KERNEL, pages, PAGE_SHIFT); +} + +/** + * vm_area_unmap_pages - unmap pages inside given vm_area + * @area: vm_area + * @addr: start address inside vm_area + * @count: number of pages to unmap + */ +int vm_area_unmap_pages(struct vm_struct *area, unsigned long addr, unsigned int count) +{ + unsigned long size = ((unsigned long)count) * PAGE_SIZE; + unsigned long end = addr + size; + + if (WARN_ON_ONCE(!(area->flags & VM_SPARSE))) + return -EINVAL; + if (addr < (unsigned long)area->addr || (void *)end > area->addr + area->size) + return -ERANGE; + + vunmap_range(addr, end); + return 0; +} + int is_vmalloc_or_module_addr(const void *x) { /* @@ -3822,9 +3870,9 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count) if (flags & VMAP_RAM) copied = vmap_ram_vread_iter(iter, addr, n, flags); - else if (!(vm && (vm->flags & (VM_IOREMAP | VM_XEN)))) + else if (!(vm && (vm->flags & (VM_IOREMAP | VM_XEN | VM_SPARSE)))) copied = aligned_vread_iter(iter, addr, n); - else /* IOREMAP|XEN area is treated as memory hole */ + else /* IOREMAP|XEN|SPARSE area is treated as memory hole */ copied = zero_iter(iter, n); addr += copied; @@ -4418,6 +4466,9 @@ static int s_show(struct seq_file *m, void *p) if (v->flags & VM_XEN) seq_puts(m, " xen"); + if (v->flags & VM_SPARSE) + seq_puts(m, " sparse"); + if (v->flags & VM_ALLOC) seq_puts(m, " vmalloc");