From patchwork Mon Feb 26 14:35:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 13572279 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 9E21CC48BF6 for ; Mon, 26 Feb 2024 14:35:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A8486B00A1; Mon, 26 Feb 2024 09:35:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 158D66B00A3; Mon, 26 Feb 2024 09:35:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3BD76B00A5; Mon, 26 Feb 2024 09:35:29 -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 E42576B00A1 for ; Mon, 26 Feb 2024 09:35:29 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B096940926 for ; Mon, 26 Feb 2024 14:35:29 +0000 (UTC) X-FDA: 81834203178.26.0963696 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf30.hostedemail.com (Postfix) with ESMTP id DABAF80019 for ; Mon, 26 Feb 2024 14:35:27 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BzH6Ppj2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of jiangshanlai@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=jiangshanlai@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708958127; 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=R7SpjWW3M3VT8K4eO43rbegmmX62zA+So7hwLN6Ereo=; b=NZxaXJaW7KmmYuerk+7v5kC5XwhGez9+EggLTowyf2ABRlwDcAYwdXucqTggZc4ge5EZ6O rPqgEYnAjuM82f4Iu3D0Kv+hIF3BORleyQ+FVmVqltACjMnwGz5rQPBf7AvRTvPZhq376e OUYqSGUDjlU5uqXPB4Vgix0E7pz9NbY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BzH6Ppj2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of jiangshanlai@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=jiangshanlai@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708958127; a=rsa-sha256; cv=none; b=jD0qcNrLmRw/nczM2qC2H6NhWzh2argCedB5pwUWERALtkH3I4M2ynko1qBrrV/H+9IguQ tSBohN1FnIVrxDUM9j+HZV6r7AwJFik7zAudGFkYKlgJac6CLDc/eUMbCORmKCChkcHoAI tnK8FNJqrHaYhbMMWzCnKl1oKa+5QtE= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e4560664b5so2524799b3a.1 for ; Mon, 26 Feb 2024 06:35:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708958126; x=1709562926; 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=R7SpjWW3M3VT8K4eO43rbegmmX62zA+So7hwLN6Ereo=; b=BzH6Ppj2E0Fk1H73kvizOe13kdqr11WWmwuTsRiXLuZrb3165oy49DpU4soX40CgZC TldTgvOcVXP+JnDqyL9g2QlOjQ40MNHh1dy/m0S8wrPyWyddWK5xKHQgNSLITekJZpQM Ct//TeSmSa7nmOHxdjHrO/UMUkcHpM1/vkGIJiLhCLCUIfDK3G5442DZ7lJGTfxpt156 y/QLO9sLupbvfBObavLrjAPF32gsjyNK9O3ykCV3kGI5K0FrABCCQeuYj4OizoIEbY4+ 4rMaiH9LvufscOE1ND0A8RnQpKuyccBKitLK9ZLbzOantfTTSSu3DLSe9J8X8fndQ8+y Tj0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708958126; x=1709562926; 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=R7SpjWW3M3VT8K4eO43rbegmmX62zA+So7hwLN6Ereo=; b=Kp1uCCkpUysFTH74LPYY3xmH8WI115bhMsxV2ccZvg/yhAsfoI5hzrT2/TWvSfTfEO BRwxAtNqw3mFkZg7Fw/RPwfoPdBDNALOhmwpz9x5EElLDDhVueTpDFkeb9lAiQ8inMcP Zl9gmaUmucjjKhExB3d6i36117rZ4uEC8nLLgHuZr9rj8FgxXDJ58GPPupNQU/v6/2sA FC1yJdMkB35Fidxb4wPxPOn6q7PElWQIJoSf7LAU8LYY9KjOU8+vt082uAf8+e80IhcN +UTOl09H1O6RTH2muVaTmIT56CpiOev71X7E+Zt8Xlhf1FQNljJZoxeyErZG1IhaY5ZD aY7A== X-Forwarded-Encrypted: i=1; AJvYcCUNc4fashbCKJKWtTMgQyV/1lELj5BAs/sW1A5clwM7oPMBXmmNdtEKuGoSuj6m5TH3SbkaynHNyZjHD5mgf2rTX/M= X-Gm-Message-State: AOJu0Yxz79vxZXK4z9pNhHQdonBTmEOTc6z19sPrMwF541VX+ehl6bzp Gyl9O74YB6wnM/KyJtxzwKJhHuMRxmwUZ2YGBL4Rhc60ynuZIR83 X-Google-Smtp-Source: AGHT+IGxAib7PTEOyHxSwfGQM+HxjrBdjOJVRLrLNJZ8c+/eWVFjsZhC6aQYApF7JqdEKo6G4JQCnw== X-Received: by 2002:a05:6a00:92:b0:6e5:9a7:34b1 with SMTP id c18-20020a056a00009200b006e509a734b1mr5652064pfj.4.1708958126496; Mon, 26 Feb 2024 06:35:26 -0800 (PST) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id fn7-20020a056a002fc700b006e4e7cafd65sm4076819pfb.42.2024.02.26.06.35.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2024 06:35:26 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Hou Wenlong , Lai Jiangshan , Linus Torvalds , Peter Zijlstra , Sean Christopherson , Thomas Gleixner , Borislav Petkov , Ingo Molnar , kvm@vger.kernel.org, Paolo Bonzini , x86@kernel.org, Kees Cook , Juergen Gross , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , linux-mm@kvack.org Subject: [RFC PATCH 15/73] mm/vmalloc: Add a helper to reserve a contiguous and aligned kernel virtual area Date: Mon, 26 Feb 2024 22:35:32 +0800 Message-Id: <20240226143630.33643-16-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240226143630.33643-1-jiangshanlai@gmail.com> References: <20240226143630.33643-1-jiangshanlai@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 433ss3jz4h8habj4583w6s4rt73fsqum X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DABAF80019 X-HE-Tag: 1708958127-334612 X-HE-Meta: U2FsdGVkX1+LFOASMlcv+4ADOnIAnBWZYQf47SAzQW9cLImE6YVyOwUltn8XVNEM1vsYJ2FQc4L5HDlCVJ/zO/tsPnToEC6jjzmklvyvWfCxB1WLqJmzqDps2dlEQ7vRva7t/zBTD77/pauw8RHv36jBgyURcBR9ouS6+nzzxExEWTMHSR/+onyQkE0nbvVlxJzzfTmQpxwuCVkDNXeFnGYo4uPgMEDq8O6tA41y3ZryLfiudYjezj/0FMX8bceLVZ9hVlAvsRYKm58TZYGdCDI7NeL6Au6OWflh4DKyKdlWnCPKWs1xwIX2gdsEh30nj0kJM6W9BcjsOYXfEMM5YWT3RyG4GjfMKL1k0PN1BTPYcfq5oUcHCqhZZc5u4597NZAmJ3DFHrCXtyZ5ggF+oA2imQ0Xhy2dJuUZ9aRAQTOG9L9ojbVGbr79CD0gKA3f4QPE7PnuyvbGh89B2F5GkBsLbUtds5Prk7lzrijVfPKH4Tmc0Kjbc0by5j/BrjfELgLi1lMCVFQAEDit7JGO7RhSm10A3m3O5Gs88YeR09kza0vMriK2XFOgbQ/sv9Bv+NoVvLqReXclcJYWjQB+A8lLqPrqr7S/SOoOVXsAFURLyfW8gZwgbqMy7X1ZnZ2zKDSIM/RL+WVSE64hM7+ZjSzbNEhdWD81DnWPa0KyZbitbWlyp6rSocTvx9qf8l8hYgFCsRgmvol05XoCGx3YlhPizoVK1i9bHZvR5UrM3HOcQZXJ6IZFJZ9neiIU0eH3pd23uGYeEHMVJ4M2woWp0kRy0Kw/9D+Rcsg7A9ihnHH4HJDwEWEPn1xEWkQS/rxKXpULPljguvG7iZPRUcei0AmdMl546okDf9Lk+AlirrrqWe5i/yEk8ZXBtT3mNSiw4dKkZnLCgmtE01bCLfLcSUoH5TuV8Owf4ICRBXgVgsV++LTPfzPayTxBJbw9I5iVO112tkG7QifL66tWvTr 8hy8JiMG pCIon48TjMMMcU5+9hwJDpLIdBR2oeDCMXLgcmyQ8eWiDND677ILC6C7sU31ioi2kszbEA8dAUDpcUq2o+EJaBPj5+2S642d0+lbgwzcABKPhUtYTa40lduxiQg== 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: Hou Wenlong PVM needs to reserve a contiguous and aligned kernel virtual area for the guest kernel. Therefor, add a helper to achieve this. It is a temporary method currently, and a better method is needed in the future. Suggested-by: Lai Jiangshan Signed-off-by: Hou Wenlong Signed-off-by: Lai Jiangshan --- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index c720be70c8dd..1821494b51d6 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -204,6 +204,8 @@ static inline size_t get_vm_area_size(const struct vm_struct *area) } extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags); +extern struct vm_struct *get_vm_area_align(unsigned long size, unsigned long align, + unsigned long flags); extern struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, const void *caller); extern struct vm_struct *__get_vm_area_caller(unsigned long size, diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..6e4b95f24bd8 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2642,6 +2642,16 @@ struct vm_struct *get_vm_area(unsigned long size, unsigned long flags) __builtin_return_address(0)); } +struct vm_struct *get_vm_area_align(unsigned long size, unsigned long align, + unsigned long flags) +{ + return __get_vm_area_node(size, align, PAGE_SHIFT, flags, + VMALLOC_START, VMALLOC_END, + NUMA_NO_NODE, GFP_KERNEL, + __builtin_return_address(0)); +} +EXPORT_SYMBOL_GPL(get_vm_area_align); + struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, const void *caller) {