Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1495285rwb; Thu, 8 Dec 2022 11:21:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HefYKJlu6z2+cDLTOqOs+duUntbxPNxklaMdWbh6vbzb8Oy2A48ZPl8I/MwJ+jFbud5VL X-Received: by 2002:a17:90a:e60c:b0:219:cb78:769e with SMTP id j12-20020a17090ae60c00b00219cb78769emr20781439pjy.114.1670527275700; Thu, 08 Dec 2022 11:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670527275; cv=none; d=google.com; s=arc-20160816; b=v2fK1QB7bZOJioz1G9sq++zR9RuBDqwX0qgc5D9VPuM4PPmV5WTJ+Q5x3iIOsDNt3U B+yWwcBxQeUwx4braKuhHL+UyTA9rWOTZWvnK+M306M11trnUhJYz47dvVd332qyoH6f DBxEHP3Bi3pNDkY6ZIzabTRSRs2EdvsUblweEo8BTuhvV32Jf4enRpbhbaAx+50triyk A2coUNiBZWWSqDVUpCeth0jChApzdNmo9Y1G0COX04gWJ/+X0TLT9xuso7EFJwO8xDAq Q6MkPXxPqMcYaFKfMSzaviXWaLoeaqx+ErFl/I+g/F4b49BK9MzyWIkVRvpK38YUc3I6 kPLA== 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=+qj/hgsudAsSQeQjwLgM7Er96xTBcPfba5POCbUPtwA=; b=YpkfdOUUa1kQ4EbbMHq9K7hTTQhXlhJwgxg8PDPHevsEGrn0rBxIxe9o8hbCvtDYSk 7t0buTc+P8K7LNYA9wUgRPtC3WDkjNHpe531egRvH558WeIqbxIj/O1lZlmfyov8TBo0 3vHTALsQ8A2dTjdM9805siOZB49Cj3ECy9s72ILSobIWPzccIiBLpxYIrtW1w5GHRqos zSVtP7+yk9iMUDcBA9zbP01t5Qkm5SZmwSCGuvBtnCfObYDoafMPt7uSnTogPECI0OH7 fXFuGk5q1V78FbPdX82hMsw4585paCmYwHMrVpgUF/DoCnozpIjM/utju9x7SYi4doQJ 37JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OZuydJPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r10-20020a63d90a000000b004787004c8dasi22531516pgg.123.2022.12.08.11.21.05; Thu, 08 Dec 2022 11:21:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OZuydJPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229943AbiLHTCF (ORCPT + 72 others); Thu, 8 Dec 2022 14:02:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiLHTCD (ORCPT ); Thu, 8 Dec 2022 14:02:03 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7448BD32 for ; Thu, 8 Dec 2022 11:02:02 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id js9so1448544pjb.2 for ; Thu, 08 Dec 2022 11:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; 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=+qj/hgsudAsSQeQjwLgM7Er96xTBcPfba5POCbUPtwA=; b=OZuydJPyQ7RHibQ69DK8aLxuHXUNvSGO5obZIQv0KYH19XsbkQC1aG0MlCb9PZfWCX WANqzP3qFui9udWh/088tR7qgAyIVZwDGFo6GozIXGCty6MttKLjyVr6Wzvr+QVAH/AF 6CxPB1pZJI35PWxIXsUk570n/LIoeqNl0mKpWtUxBSngeOqY8WIEIU+b2qKpqC3mmnRL Dve6GGtJOchEaa/us9OjD0lEqWy44kquFqcZs3uIXXlcOMAgUVCnkwQK7KWcE65oXveM 9+OVSAKOLGY8YdAZ+y4D4olEzaD3AMRaIj6tQqRenz46uiGZ8DQ8PpV10U+fjEiVoNcZ 6j8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+qj/hgsudAsSQeQjwLgM7Er96xTBcPfba5POCbUPtwA=; b=Pz2qTatQpGkm/roz4J5kFj56BoYLHC16RTCDqabwB+vS265pYL1q0pSg2+jfiiqhNS pcuTEsUGUcxzuWPT0wcJwihqZrPTTqL8Y3LkHJ8C8gOIaBTeBBbN6rQSvpgMoJn2hgB3 oCSIFhqBCXXBIsdMLbP+X9IVGevgngNlLo2UErzQOSZZJl7d5EY1Vc7VxvHsR3zNQeEF eDOl226PdB8sPQDkUenaGI8G1YZbeiIYoJtNMnJ9PVW7xuJdsq5jgtG/LPTccg8ou3qn ul40b1hknkXu9Z/3CHKcCCbQ3SvmN3aXPim911TF9J7sxhES8iL8N7V1rWIHKiBiSgQA gFYQ== X-Gm-Message-State: ANoB5plb3XWAhcX6rqIIFB5bBpQ2oOto4+lcx1U+n2HcrsuEqKun0sAn kh7dWuoDsyRJBANSW9C8Y4P6EQ== X-Received: by 2002:a17:902:7402:b0:189:58a8:282 with SMTP id g2-20020a170902740200b0018958a80282mr1565905pll.3.1670526121972; Thu, 08 Dec 2022 11:02:01 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id u17-20020a170902e81100b0018996404dd5sm5999822plg.109.2022.12.08.11.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 11:02:01 -0800 (PST) Date: Thu, 8 Dec 2022 19:01:57 +0000 From: Sean Christopherson To: Ricardo Koller Cc: Oliver Upton , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Shuah Khan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] KVM: selftests: Setup ucall after loading program into guest memory Message-ID: References: <20221207214809.489070-1-oliver.upton@linux.dev> <20221207214809.489070-3-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 08, 2022, Ricardo Koller wrote: > On Thu, Dec 08, 2022 at 12:37:23AM +0000, Oliver Upton wrote: > > On Thu, Dec 08, 2022 at 12:24:20AM +0000, Sean Christopherson wrote: > > > > Even still, that's just a kludge to make ucalls work. We have other > > > > MMIO devices (GIC distributor, for example) that work by chance since > > > > nothing conflicts with the constant GPAs we've selected in the tests. > > > > > > > > I'd rather we go down the route of having an address allocator for the > > > > for both the VA and PA spaces to provide carveouts at runtime. > > > > > > Aren't those two separate issues? The PA, a.k.a. memslots space, can be solved > > > by allocating a dedicated memslot, i.e. doesn't need a carve. At worst, collisions > > > will yield very explicit asserts, which IMO is better than whatever might go wrong > > > with a carve out. > > > > Perhaps the use of the term 'carveout' wasn't right here. > > > > What I'm suggesting is we cannot rely on KVM memslots alone to act as an > > allocator for the PA space. KVM can provide devices to the guest that > > aren't represented as memslots. If we're trying to fix PA allocations > > anyway, why not make it generic enough to suit the needs of things > > beyond ucalls? > > One extra bit of information: in arm, IO is any access to an address (within > bounds) not backed by a memslot. Not the same as x86 where MMIO are writes to > read-only memslots. No idea what other arches do. I don't think that's correct, doesn't this code turn write abort on a RO memslot into an io_mem_abort()? Specifically, the "(write_fault && !writable)" check will match, and assuming none the the edge cases in the if-statement fire, KVM will send the write down io_mem_abort(). gfn = fault_ipa >> PAGE_SHIFT; memslot = gfn_to_memslot(vcpu->kvm, gfn); hva = gfn_to_hva_memslot_prot(memslot, gfn, &writable); write_fault = kvm_is_write_fault(vcpu); if (kvm_is_error_hva(hva) || (write_fault && !writable)) { /* * The guest has put either its instructions or its page-tables * somewhere it shouldn't have. Userspace won't be able to do * anything about this (there's no syndrome for a start), so * re-inject the abort back into the guest. */ if (is_iabt) { ret = -ENOEXEC; goto out; } if (kvm_vcpu_abt_iss1tw(vcpu)) { kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu)); ret = 1; goto out_unlock; } /* * Check for a cache maintenance operation. Since we * ended-up here, we know it is outside of any memory * slot. But we can't find out if that is for a device, * or if the guest is just being stupid. The only thing * we know for sure is that this range cannot be cached. * * So let's assume that the guest is just being * cautious, and skip the instruction. */ if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) { kvm_incr_pc(vcpu); ret = 1; goto out_unlock; } /* * The IPA is reported as [MAX:12], so we need to * complement it with the bottom 12 bits from the * faulting VA. This is always 12 bits, irrespective * of the page size. */ fault_ipa |= kvm_vcpu_get_hfar(vcpu) & ((1 << 12) - 1); ret = io_mem_abort(vcpu, fault_ipa); goto out_unlock; }