Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp246128rdh; Thu, 23 Nov 2023 02:59:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcWZjoUY57GQ3dXGMAsG3UHQNbFn6aZS+vfCW++/+SSPtXSNY3yqFda16V6o+kf3DRYQ1Q X-Received: by 2002:a05:6a20:8f06:b0:18a:df69:eabe with SMTP id b6-20020a056a208f0600b0018adf69eabemr3326036pzk.11.1700737139781; Thu, 23 Nov 2023 02:58:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700737139; cv=none; d=google.com; s=arc-20160816; b=GOPbpB8U9CxI2LfUFreBEDyaxq/iy6kM4f4O/jv0oWXehmStIRTRa76yOmadMY/ot1 8IqAYPchF5zqjqUH3+HnJCJomcKVnHSfP0Re2uOIjcY7dn0cZEuEBVOp8mOJD69y7KZN Ugb9lGg3W8bqr53B6n2ce6aKuOz1TSyApEmNNO++GmxQ2jaY+T0XcGRmByEgyo0Ye/z1 tSz8JxBkoNiAi3Xf7gUVolwq//dv/5TiQHam/msjdNMmMp0ELngLk2mzAATJZDuqqz20 l8fPt6mjm1b5Dm66kNcKNuU4bxOQH1slRj9mbauODxfjB8Q4tZ6i2vKwgP6sBEED1uCh KRKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tbD+CZLI2OJnj2XtkqlWGnXInTbmUcqYNyaWG++MW1o=; fh=QuYwfXyQrQ0cYQPT4F4EO0wzMHthjERDPjd6zE8cmaQ=; b=vMwH7aKcEjxpHREcBYCmoH77DfydVZdO7t/c/TWA3+4boUtSoogpKW7u//iHam/JBd mj2kzmxi/yjvY5MDBxDxosWG2XCzQIatge0OVyDkaZK/vdEK0XvmKMv1qY9MqBMyPB+S J1n5BjaIriCDOEzZ6P7rH3HXLt1Go/5eyCvr6wK+B70FV8Z4o3cyFhV39MvUSeAuapgp mSQP8StJc7iuBJJ1M6LLe4jjzl+MNeRgnOzEkqbV5A3euQbU/Z8ZYCbyyQj6RVyfxDF9 VHyFioiquOnpjesrThUWJ8MJ5SRVA/79sM8xg3drvU8zJi5ytpOKUP7b/C6qNJ6YSZ97 zNRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HiCbmO1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id s1-20020a63e801000000b005be09b723b7si1080422pgh.636.2023.11.23.02.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 02:58:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HiCbmO1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B5E76825A868; Thu, 23 Nov 2023 02:58:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbjKWK6X (ORCPT + 99 others); Thu, 23 Nov 2023 05:58:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235191AbjKWK6S (ORCPT ); Thu, 23 Nov 2023 05:58:18 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2314BD5A for ; Thu, 23 Nov 2023 02:58:24 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b36b9d9faso25485e9.0 for ; Thu, 23 Nov 2023 02:58:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700737102; x=1701341902; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tbD+CZLI2OJnj2XtkqlWGnXInTbmUcqYNyaWG++MW1o=; b=HiCbmO1BCtoKlVmh18VYckeBAc5s9WLFAyvriomLKnssA+fkK10s+kuXB7ezYpIP3+ 2V+SajP1cU0De+rGG9wS6QlfJDJC5gOkJ1uJCS6z7chJKc+jE1rOg4FAA8xiEjHgTTN4 TQs1qwRT3o0oIs7xuTiUdCddU4q712zXF9r6oEi40DBB7nrE3TOSfIQB7nx32+n2cEjW Pb8Zsc92s/U5XmbkktMs1FKtqlumC2e7ifoXgmEhvTFqehNIJoQmCyIdMq6uzf1yYUY5 wjzEm3K8Dhd84efV+bmIor0+DkSKy/Ksj7ga1g7bP3Q67F1XQiFWzr40S30t4+Qy7YnH vy5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700737102; x=1701341902; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tbD+CZLI2OJnj2XtkqlWGnXInTbmUcqYNyaWG++MW1o=; b=pk1RUF+4t719C4GHNfGQbC6Zf9dzwqi8/9dEgqh3NaCmh5GMPCHnL0l1YFabII4J43 YBKSY7G3Zqsl7AyBfh5f6l/S1rR+XTS5ZUNbX7E+BTiOkiu0X48OoR12515eEEBPP0Vx SfSlBK1oA184MsOegt7SPOuYxROrYmuNuphlGw0Nc47dMEAVV/rlI9LXZ3A4GBbEA/l2 1pIrkxbBfElafZYluxtRPUFoxOET9rUrm2AtFgwGZEEnX+3qYLPWRuk01OyrbdIYR8HU 59vzLv+ne1Heoi0GEKpG22yDeNuoIOdZAio+Kgjq9W2lmbjOztpXFzJwXcUl52UdYYZQ f09g== X-Gm-Message-State: AOJu0YywNGxoRo5RXm8YGcPiCU2eKu5Qjn9HAUgq8LXnaTrVz3WQkJyM aRms3mbqRk5VF29N4PEdm8RACg== X-Received: by 2002:a05:600c:3b13:b0:40a:483f:f828 with SMTP id m19-20020a05600c3b1300b0040a483ff828mr251605wms.4.1700737102403; Thu, 23 Nov 2023 02:58:22 -0800 (PST) Received: from google.com (110.121.148.146.bc.googleusercontent.com. [146.148.121.110]) by smtp.gmail.com with ESMTPSA id k11-20020adfe3cb000000b00332d3c78e11sm1305204wrm.85.2023.11.23.02.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 02:58:21 -0800 (PST) Date: Thu, 23 Nov 2023 10:58:20 +0000 From: Sebastian Ene To: Oliver Upton Cc: will@kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com Subject: Re: [PATCH v3 10/10] arm64: ptdump: Add support for guest stage-2 pagetables dumping Message-ID: References: <20231115171639.2852644-2-sebastianene@google.com> <20231115171639.2852644-12-sebastianene@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 23 Nov 2023 02:58:56 -0800 (PST) On Wed, Nov 22, 2023 at 11:35:57PM +0000, Oliver Upton wrote: > On Wed, Nov 15, 2023 at 05:16:40PM +0000, Sebastian Ene wrote: > > +struct ptdump_registered_guest { > > + struct list_head reg_list; > > + struct ptdump_info info; > > + struct kvm_pgtable_snapshot snapshot; > > + rwlock_t *lock; > > +}; > > Why can't we just store a pointer directly to struct kvm in ::private? I don't think it will work unless we expect a struct kvm_pgtable in stage2_ptdump_walk file_priv field. I think it is a good ideea and will simplify things a little bit dropping kvm_pgtable_snapshot from here. The current code has some fileds that are reduntant (the priv pointers) because I also made this to work with protected guests where we can't access their pagetables directly. > Also, shouldn't you take a reference on struct kvm when the file is > opened to protect against VM teardown? > I am not sure about the need could you please elaborate a bit ? On VM teardown we expect ptdump_unregister_guest_stage2 to be invoked. > > +static LIST_HEAD(ptdump_guest_list); > > +static DEFINE_MUTEX(ptdump_list_lock); > > What is the list for? > I am keeping a list of registered guests with ptdump and the lock should protect the list against concurent VM teardowns. > > static phys_addr_t ptdump_host_pa(void *addr) > > { > > return __pa(addr); > > @@ -757,6 +768,63 @@ static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) > > kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); > > } > > > > +static void guest_stage2_ptdump_walk(struct seq_file *s, > > + struct ptdump_info *info) > > +{ > > + struct ptdump_info_file_priv *f_priv = > > + container_of(info, struct ptdump_info_file_priv, info); > > + struct ptdump_registered_guest *guest = info->priv; > > + > > + f_priv->file_priv = &guest->snapshot; > > + > > + read_lock(guest->lock); > > + stage2_ptdump_walk(s, info); > > + read_unlock(guest->lock); > > Taking the mmu lock for read allows other table walkers to add new > mappings and adjust the granularity of existing ones. Should this > instead take the mmu lock for write? > Thanks for pointing our, this is exactly what I was trying to avoid, so yes I should use the write mmu lock in this case. > > +} > > + > > +int ptdump_register_guest_stage2(struct kvm *kvm) > > +{ > > + struct ptdump_registered_guest *guest; > > + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; > > + struct kvm_pgtable *pgt = mmu->pgt; > > + > > + guest = kzalloc(sizeof(struct ptdump_registered_guest), GFP_KERNEL); > > You want GFP_KERNEL_ACCOUNT here. > Right, thanks this is because it is an untrusted allocation triggered from userspace. > -- > Thanks, > Oliver Thank you, Seb