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 X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9C90C433E0 for ; Fri, 12 Mar 2021 10:15:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7170964FF9 for ; Fri, 12 Mar 2021 10:15:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7170964FF9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=awY3QKbv7NMHopjmjLQ5c3BE7DaqbE5xGO8+q9DtK5Y=; b=WRE1iHVir2DuX8LRJRzfvasqp h5rihHOITPnlaVzOgnYS1Zh9YZ3FKbliSd1+ez8ePyh5l55so/GpFgzuESD1tr1kmjfCInRdQtQAl EIfTufL7KEntd/mz+3KWr9gPAUkitFA2fNIqlcz0N2PP+v9TJ4khreG//N0oVVJ+dxIzsRn9Y8xzp tMAYCvQvHm73opIjyNSfii1gCkuXmeoa3j5TvdavCBQeiq10gNqr6OQ+Dc4oynxddddgbpVZkknGl eyt+CCrMnVp5giand1YEZEvundUu1Jh3AokKApfW7vkPWv9oYO9PjkyBWFWF3n30eUxv66iOehh9w tdz7qTzng==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lKeng-00B86S-FT; Fri, 12 Mar 2021 10:13:44 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lKenV-00B83w-QS for linux-arm-kernel@lists.infradead.org; Fri, 12 Mar 2021 10:13:36 +0000 Received: by mail-wm1-x331.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso15433361wma.4 for ; Fri, 12 Mar 2021 02:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dOH5AK+PAfRAsg2dxAdQE8C774VeCltqpKz+okkVeFM=; b=OQyevQU51Wt1xnh2LbX/w1hCSfiwz6KAaijoqwJz0R8Wjxrl8Uep70/qnj/OCN76EJ zF1lDsjWFBn//WEW76/aHd88jg2/A3oLTLTdCoEH41VqrLnPwfka/vDfXzhgvKKz2hwh Bw5aWs/xlmjzVaxZfgDMnWoYGONap/ih6d6St4+g2PG9ckB2n1Sh7VojdF0bX3prNspp kOjtaPujuw5izKVEhe6VmVy5Ut/10+gwAMKKGLJsN52lPb6tkRsQFegz3mLkvdUqs7Gl 69DP+TmO9mqm0hSj6w62fHZEarnptc9hBY8JXn2fANa1fWzKp4/xHqI1UndehrCgdbcv oJKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dOH5AK+PAfRAsg2dxAdQE8C774VeCltqpKz+okkVeFM=; b=P4mb+4+sgdp+sdoIcGveqIqHbGvjEpuyhA2eF9f6xrfvzGxqMz0xZZdNuNp3KZOx6i siXT6rlRoVls2e/4iy6yDpUkvRTqeQLGDKSAPcO+nUl3ya1ZcNOqF4VUYjgtpZlrGglq TRw/410exY5F2cfn2UGeDjIziJyln7GdjFsE7+2CQOv3epdBIsJa4xbwHO4QBLNl/rnU TEh6YXEw2powLwf3XHW8f6D+VKkoF9JNh90WnablEhMq87mvqrCmvzPD9d13edGedTGi zNPI8k1m7hUoKGtu9PryT+IITluOvAYrtW/rTLXZQQ7JL8RLjqKDYFE3gshCdhUw546r 1K2g== X-Gm-Message-State: AOAM530aR3XhLzkvKuRx5D6sX341PTanx3l8CShZOKl0kfFWuj+QzUUf SgI1Xb7nEt1KdnGuWvRlYbvD0A== X-Google-Smtp-Source: ABdhPJzs2CwFIhMIFHCtWhF0Kk8Mn96x94X3sQBAAfKwNZIrb+5CYxK9LtqpnTzDcLxhgVyEpFqTlw== X-Received: by 2002:a05:600c:224e:: with SMTP id a14mr12231304wmm.57.1615544012774; Fri, 12 Mar 2021 02:13:32 -0800 (PST) Received: from google.com (230.69.233.35.bc.googleusercontent.com. [35.233.69.230]) by smtp.gmail.com with ESMTPSA id h25sm1933615wml.32.2021.03.12.02.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 02:13:32 -0800 (PST) Date: Fri, 12 Mar 2021 10:13:26 +0000 From: Quentin Perret To: Will Deacon Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, robh+dt@kernel.org, ardb@kernel.org Subject: Re: [PATCH v4 28/34] KVM: arm64: Use page-table to track page ownership Message-ID: References: <20210310175751.3320106-1-qperret@google.com> <20210310175751.3320106-29-qperret@google.com> <20210311183834.GC31378@willie-the-truck> <20210312093205.GB32016@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210312093205.GB32016@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210312_101334_001062_8455F36E X-CRM114-Status: GOOD ( 37.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Friday 12 Mar 2021 at 09:32:06 (+0000), Will Deacon wrote: > I'm not saying to use the VMID directly, just that allocating half of the > pte feels a bit OTT given that the state of things after this patch series > is that we're using exactly 1 bit. Right, and that was the reason for the PROT_NONE approach in the previous version, but we agreed it'd be worth generalizing to allow for future use-cases :-) > > > > @@ -517,28 +543,36 @@ static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, > > > > if (!kvm_block_mapping_supported(addr, end, phys, level)) > > > > return -E2BIG; > > > > > > > > - new = kvm_init_valid_leaf_pte(phys, data->attr, level); > > > > - if (kvm_pte_valid(old)) { > > > > + if (kvm_pte_valid(data->attr)) > > > > > > This feels like a bit of a hack to me: the 'attr' field in stage2_map_data > > > is intended to correspond directly to the lower/upper attributes of the > > > descriptor as per the architecture, so tagging the valid bit in there is > > > pretty grotty. However, I can see the significant advantage in being able > > > to re-use the stage2_map_walker functionality, so about instead of nobbling > > > attr, you set phys to something invalid instead, e.g.: > > > > > > #define KVM_PHYS_SET_OWNER (-1ULL) > > > > That'll confuse kvm_block_mapping_supported() and friends I think, at > > least in their current form. If you _really_ don't like this, maybe we > > could have an extra 'flags' field in stage2_map_data? > > I was pondering this last night and I thought of two ways to do it: > > 1. Add a 'bool valid' and then stick the owner and the phys in a union. > (yes, you'll need to update the block mapping checks to look at the > valid flag) Right, though that is also used for the hyp s1 which doesn't use any of this ATM. That shouldn't be too bad to change, I'll have a look. > 2. Go with my latter suggestion: > > > > Is there ever a reason to use kvm_pgtable_stage2_set_owner() to set an > > > owner of 0, or should you just use the map/unmap APIs for that? If so, > > > then maybe the key is simply if owner_id is non-zero, then an invalid > > > entry is installed? > > > > I couldn't find a good reason to restrict it, as that wouldn't change > > the implementation much anyway. Also, if we added the right CMOs, we > > could probably remove the unmap walker and re-express it in terms of > > set_owner(0) ... But I suppose that is for later :-) > > The idea being that if owner is 0, then we install a mapping for phys, but > if owner is !0 then we set the invalid mapping. And I could even special-case set_owner(0) by calling unmap under the hood so the caller doesn't need to care, but it's a bit yuck. > (1) is probably the less hacky option... what do you reckon? Agreed, (1) is a bit nicer. I was also considering setting phys = BIT(63) in the set_owner() path. That makes it obvious it is an invalid PA, and it should retain the nice alignment properties I need. But I suppose an explicit flag makes it easier to reason about, so I'll have a go at it. Thanks, Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel