[RFC,15/73] mm/vmalloc: Add a helper to reserve a contiguous and aligned kernel virtual area
Message ID | 20240226143630.33643-16-jiangshanlai@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-81657-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2142185dyb; Mon, 26 Feb 2024 07:15:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUk/q5U9UvREdokfFzYjO9yMfYH8JuAOErKFRiu+kRhdJJDp5Y/T0JWSNadsraX0WIxyFTzehxDqAX0d0w9rO39rcVFcg== X-Google-Smtp-Source: AGHT+IHXQ0KQ8rXQLz+Q+PZweA1wfDTd4jHQ4SuDTbTsupcC6vY9/KdMacGqQXz50zeQz9ZWALti X-Received: by 2002:a05:6a20:af87:b0:1a0:7e2f:ad44 with SMTP id ds7-20020a056a20af8700b001a07e2fad44mr7777842pzb.31.1708960543342; Mon, 26 Feb 2024 07:15:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708960543; cv=pass; d=google.com; s=arc-20160816; b=x507+D14NFfOnJXjLJPbcq8zVqbu4oNfLAXAY+3mFDj2mMTm1JJQ77hpq9Kvh6HuGA m4jMJqoiPuUsJSBjhWUoHuO+UjfQQJQ3bOKcOZTzsDwbQeQmRrN5ooFRP/G3jOgtaYUM 00BGQepYJV13RMednTiEdu0LV3OC1CzWSNkDf26hFZW/g8bn3ya0yiDFjUYjJT0xsjT8 YrxAcjYp7XPGAnJ3olrcLg8g0YkZqschparbiT2QH0B3EpvD4TkpkUKriX+L3eq59zjo 4+kkKCB8L3U6TrtmpiEvHTt+jVfVTK7BXfdusbk5hDi+wZcy1WigIuYCIYegkinwZre8 P1qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=R7SpjWW3M3VT8K4eO43rbegmmX62zA+So7hwLN6Ereo=; fh=bzSjDIt/L5nz087jy+59GrpPu4BWR0eSrS4gvts0+Qg=; b=Ck3xvK05Hu5UClAo/alYeHfPkpzTP0ESLFdDBd5387cP8ELz0k1duIuz8DzNYtEqYN AxmKHRIzx52gRyxxUIXeCneCj21t7Q9ILKUfrlfmgCv2BQ+VrgmOuXlWqeds3ezPlrbf FRf3in3UChI1C+umW8353Fx8wSHTUiSOeBjJudWePRRa1yOjBkWwy9YPOR4SvRRR+oZk JClP2IIA77XdHE3ZskvEiTHyJWDgI2yUrH221ymx2fdhro670crDEZJWUTghouCHaCx8 limcWibc7Koz68zcgLatqpxaCYxmDDpGo24rAp1xC4hbZDdIZyBt7pPBmAYX3qmQwo+/ ZkzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QMqw5NCR; 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-81657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81657-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q5-20020a056a00084500b006e4ba601b32si3936413pfk.211.2024.02.26.07.15.42 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:15:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QMqw5NCR; 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-81657-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81657-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9B287B21957 for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 14:41:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85127131731; Mon, 26 Feb 2024 14:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QMqw5NCR" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 5A8F5130E34; Mon, 26 Feb 2024 14:35:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958128; cv=none; b=LwdDR6wcxNfPmYMWAOuF0Z8pXQtDDPCK20SKmnLhs9O6fFWIvNLeg1xZhWybgtaX6VP5H8AF3Uj+8wa4kLVKkPkMsD7vuMOwcB4eR/N85Cv0+glSOx1jZHyuICO22iyCEsOMYAGF571XkO84dBvVyWPZtZ4/zpeTd25BEsLENeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958128; c=relaxed/simple; bh=bsV9BT402z/Bw0WTA6E9ywSofSFLcIXPfojxj3LNnZs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y5gG6KcU9pTkELrI/5hgAd5sbmycI7C+ywrRp5pV3JhfesHD9pQ4JycbXtyXdCZmDe12bpKrYfkoQMyihdZ/ukVv0ORNvyhR+48x035BxyL66+gUozSwlWlHcv9kWO+7rHdJm+RWva0YwpG0DzdJ34bp3MZbpCzUimufKJiOcz4= 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=QMqw5NCR; arc=none smtp.client-ip=209.85.210.177 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-pf1-f177.google.com with SMTP id d2e1a72fcca58-6da9c834646so3175976b3a.3; 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=vger.kernel.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=QMqw5NCR0RJRsriE0ZN9FFW2tJ0rkM6qN6R8JKYCXTn9hfxq9N40rAdpwBLVW7hSQ8 Sx6AtBEGjUTiGX+pUX/FNF3+gkT9CzQ0Ln7GnT2TQ3QksuWoEJhvKx/RwGEER5G6/2WV r7sCU8X9+daKD6Cijvvmc4oPsfrfOnJuxa7zxGVzjeMWT5jK24lSiIy4ko1UhMnAV/JV ss2wjuSUDZm+6m22bP9Za5b0SloN/MvGCHHx2NbqY37O4+pvT+rvjhA2PdV8UXkDAkY6 FVzF3RL7eVYiF4+rg0lS7y9rglLepO8b+owNHKcxw3Q7DhP7aCIlV2hl/weJb01UESDX Hs9A== 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=uHqcQruh7Z/B8TCjizlj+lyGlqdXFW3O+ob7/oQDGk1WUyD9zLqp+Ej7S3Cg6iTdA1 eW+1bsUBW6nWebACUxeuM95L3ba3ecTeADXrTLj3I0iWskLFVCKGQYSh9+UOHPTqLQiP 4W6Pf3eOCmBjouIVeCMMNjwuNO8wfT0+HY/YGpOIgYZylhaoj+YyWVWuTuOEmGO4cEA4 rj/x0Rm+gMlA+boVSwQ8uaRmyG8dXS59Ox85CsSZavMP8OeWStP7M65dLjoVMh6gJVJX EMU1zOyQ1FxrGzkqlBUlz4Yrc8s42eTlxnWris3pL0A6o5yIXighSfsR3X373lZqCUED xvZw== X-Forwarded-Encrypted: i=1; AJvYcCVxBlwQuHNGV0+DfLXfkrOlIv643BEHBgiNh4CEIr/QKE3dEQ3XbyrWqTZfbVh8BJKTI0JK2Rd+jCfJ203FgLXyLMhY X-Gm-Message-State: AOJu0Yw3TsKfykZoDyMdRhCi6oqt+rZThmbx38YTYra+DIOiHRvCpf/0 5ZWJ1NwQ7M+phEpgo28aHrM7uwfujioefUw3Al2vvN6TFOYtop+DPhVRCKbd 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 <jiangshanlai@gmail.com> To: linux-kernel@vger.kernel.org Cc: Hou Wenlong <houwenlong.hwl@antgroup.com>, Lai Jiangshan <jiangshan.ljs@antgroup.com>, Linus Torvalds <torvalds@linux-foundation.org>, Peter Zijlstra <peterz@infradead.org>, Sean Christopherson <seanjc@google.com>, Thomas Gleixner <tglx@linutronix.de>, Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>, kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>, x86@kernel.org, Kees Cook <keescook@chromium.org>, Juergen Gross <jgross@suse.com>, Andrew Morton <akpm@linux-foundation.org>, Uladzislau Rezki <urezki@gmail.com>, Christoph Hellwig <hch@infradead.org>, Lorenzo Stoakes <lstoakes@gmail.com>, 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791975011085081867 X-GMAIL-MSGID: 1791975011085081867 |
Series |
[RFC,01/73] KVM: Documentation: Add the specification for PVM
|
|
Commit Message
Lai Jiangshan
Feb. 26, 2024, 2:35 p.m. UTC
From: Hou Wenlong <houwenlong.hwl@antgroup.com> 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 <jiangshan.ljs@antgroup.com> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com> --- include/linux/vmalloc.h | 2 ++ mm/vmalloc.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
Comments
On Mon, Feb 26, 2024 at 10:35:32PM +0800, Lai Jiangshan wrote: > From: Hou Wenlong <houwenlong.hwl@antgroup.com> > > PVM needs to reserve a contiguous and aligned kernel virtual area for Who is "PVM", and why does it need aligned virtual memory space? > +extern struct vm_struct *get_vm_area_align(unsigned long size, unsigned long align, No need for the extern here.
Hello On Tue, Feb 27, 2024 at 10:56 PM Christoph Hellwig <hch@infradead.org> wrote: > > On Mon, Feb 26, 2024 at 10:35:32PM +0800, Lai Jiangshan wrote: > > From: Hou Wenlong <houwenlong.hwl@antgroup.com> > > > > PVM needs to reserve a contiguous and aligned kernel virtual area for > > Who is "PVM", and why does it need aligned virtual memory space? PVM stands for Pagetable-based Virtual Machine. It is a new pure software-implemented virtualization solution. The details are in the cover letter: https://lore.kernel.org/lkml/20240226143630.33643-1-jiangshanlai@gmail.com/ I'm sorry for not CC'ing you on the cover letter (I haven't made/found a proper script to generate all cc-recipients for the cover letter.) nor elaborating the reason in the changelog. One of the core designs in PVM is the "Exclusive address space separation", with which in the higher half of the address spaces (where the most significant bits in the addresses are 1s), the address ranges that a PVM guest is allowed are exclusive from the host kernel. So PVM hypervisor has to use get_vm_area_align() to reserve a huge range (normally 16T) with the alignment 512G (PGDIR_SIZE) for all the guests to accommodate the whole guest kernel space. The reserved range cannot be used by the host. The rationale of this core design is also in the cover letter. Thanks Lai > > > +extern struct vm_struct *get_vm_area_align(unsigned long size, unsigned long align, > > No need for the extern here. >
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) {