Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1594566iog; Thu, 16 Jun 2022 09:28:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1siH5D7QMvIyD+3NEeKsFfJ9Bx2YlWKSMuvvEXlINdW2q/QOd+oZN/lkFs7oT9cammxzlXZ X-Received: by 2002:a05:6402:34cc:b0:431:67ed:96a0 with SMTP id w12-20020a05640234cc00b0043167ed96a0mr7498834edc.372.1655396908446; Thu, 16 Jun 2022 09:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655396908; cv=none; d=google.com; s=arc-20160816; b=kGqG4k0ClZbJfpOzxYfWmTRtoek0c9k4so1fmYd3BRyUOz22sb3K67PGKTgaYvQrsE 0ekC8MdzEbzNWzoA/WR2aevJG09OipD6OzyN/uby7GZBQOHOJ3Baz/IZlpZI3VwppGId pFnaBczDcP87jcuXSpNRhcxVZEl757PGTczaflitjswXtSN5V/srhfUM+7DWTuY320Of en/3d9An7QNemL8bTpRJSUntnMDXLDKwyJiaZBm/QLo5sji465gfKCabTpsKvCWg7vza WdBDWFl4KMcMq7tCRkPT9pqV17oMRK5xRLlWsH+Wsg5ttKQa6U2nLey4OX00NA1Q9A7B C4HQ== 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=cq3EZTL12suGQBdO/AxiYch3x1bNx+94IHDi7h+Rhok=; b=ds13bH8nGPjesU9C7DL01gkDtQRznsGlAkSrrsEamWpqv7PRoSA9dMcuBwFqIT1fah nbe01F41oGVCsz6+KLKd6Qz4KPy1g8sPqpqFfvZ5vwWaQ87jZoRMGLLETNr+oX02YBPD 71ygE7BOX7q0YaCd+Z0ZnwfQbDcMN/NEkX0TCjOVLXp74QBqUPKg0nRFMfBHWVx44Wev lyq5ubvFh2Np+S0YWA84j25c4jWA6CIB29mus797cc7fzHIndbk8gWQPYd/HICH6ypnU byTo78shu6ZZs3enKbvSQxKqSXFJ3U/qId7SaVVWX22QImGiktVIW2uwHmQrl0dg9lfo XWvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d9gXLvdu; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx2-20020a0564020b4200b0042fadee7b8csi2529699edb.538.2022.06.16.09.28.02; Thu, 16 Jun 2022 09:28:28 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=d9gXLvdu; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232802AbiFPQ0H (ORCPT + 99 others); Thu, 16 Jun 2022 12:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230319AbiFPQ0G (ORCPT ); Thu, 16 Jun 2022 12:26:06 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 612DA2EA07 for ; Thu, 16 Jun 2022 09:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655396763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cq3EZTL12suGQBdO/AxiYch3x1bNx+94IHDi7h+Rhok=; b=d9gXLvdu00EYqZtFdIzNu/qXjl6xZT6JlP4rqiShGKxiddvtP/QVT0+v1T1q8Buvq9uK5G sK4WgMTViLwlZQrDXxdNMDwDwVgYZikzxwsRbFof5fIBzf6nxdq8al+D7J9nj3xbpGLxDy Qn80C5sX+zP2NipfP+HMcoIyv7UpURs= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-mpjk1zjaMseg1E8Y-7UilQ-1; Thu, 16 Jun 2022 12:26:02 -0400 X-MC-Unique: mpjk1zjaMseg1E8Y-7UilQ-1 Received: by mail-ej1-f69.google.com with SMTP id gh36-20020a1709073c2400b0070759e390fbso808869ejc.13 for ; Thu, 16 Jun 2022 09:26:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cq3EZTL12suGQBdO/AxiYch3x1bNx+94IHDi7h+Rhok=; b=F+rrJ0hcR9xHPns6BAuqwdhDzQBQ4Yw+69xAj1v9CllBOCNYiZ1WOScNHk2hXDSb64 BYKXvaW1ng3FpTRJaQbVwMc1Up/mwaWXB9EDO1/sb12JHEeZTvnAEVPvmeDu5yg48I/E UFsKYvgemgLYtT6zaywBj2ED4AZpfGIwgq+/CXCHiF9omAkUL4fmOKK3RRGmdSMZhOjV 1yquyiBDZu6bQhjwwtPyWcD+jGd0tPGV4rNFMJLlmZL6Pp2cVopPdVA7dfMaD/0qNVgB P5xwCm1+PG/pQA1hlPdKIWy3IGH9Wwx8uaSC/XmwkKM1U8y7WEt4dWojktSmbDgoafcT /Onw== X-Gm-Message-State: AJIora9VlSkE0rncsrLfgNs1qh60DluUuNKNjADjg3xhrnWVsr2BPp1a 4NRClJCJwXHX67jYdcDErT1xAT5OIAC45yxGuHrF6MEvOzXb4TamFGe8+cBzVNGVVrSBi/ZWAKv KPCYIMBBGAv1ZUygL+kLug3/d X-Received: by 2002:a17:906:ff18:b0:711:d197:b942 with SMTP id zn24-20020a170906ff1800b00711d197b942mr5233777ejb.357.1655396760902; Thu, 16 Jun 2022 09:26:00 -0700 (PDT) X-Received: by 2002:a17:906:ff18:b0:711:d197:b942 with SMTP id zn24-20020a170906ff1800b00711d197b942mr5233761ejb.357.1655396760732; Thu, 16 Jun 2022 09:26:00 -0700 (PDT) Received: from gator ([194.213.204.253]) by smtp.gmail.com with ESMTPSA id ep14-20020a1709069b4e00b006febc86b8besm936606ejc.117.2022.06.16.09.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 09:26:00 -0700 (PDT) Date: Thu, 16 Jun 2022 18:25:57 +0200 From: Andrew Jones To: David Laight Cc: Raghavendra Rao Ananta , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Colton Lewis , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.cs.columbia.edu" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Subject: Re: [PATCH] selftests: KVM: Handle compiler optimizations in ucall Message-ID: <20220616162557.55bopzfa6glusuh5@gator> References: <20220615185706.1099208-1-rananta@google.com> <20220616120232.ctkekviusrozqpru@gator> <33ca91aeb5254831a88e187ff8d9a2c2@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33ca91aeb5254831a88e187ff8d9a2c2@AcuMS.aculab.com> X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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, Jun 16, 2022 at 03:58:52PM +0000, David Laight wrote: > From: Andrew Jones > > Sent: 16 June 2022 13:03 > > > > On Wed, Jun 15, 2022 at 06:57:06PM +0000, Raghavendra Rao Ananta wrote: > > > The selftests, when built with newer versions of clang, is found > > > to have over optimized guests' ucall() function, and eliminating > > > the stores for uc.cmd (perhaps due to no immediate readers). This > > > resulted in the userspace side always reading a value of '0', and > > > causing multiple test failures. > > > > > > As a result, prevent the compiler from optimizing the stores in > > > ucall() with WRITE_ONCE(). > > > > > > Suggested-by: Ricardo Koller > > > Suggested-by: Reiji Watanabe > > > Signed-off-by: Raghavendra Rao Ananta > > > --- > > > tools/testing/selftests/kvm/lib/aarch64/ucall.c | 9 ++++----- > > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > index e0b0164e9af8..be1d9728c4ce 100644 > > > --- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c > > > @@ -73,20 +73,19 @@ void ucall_uninit(struct kvm_vm *vm) > > > > > > void ucall(uint64_t cmd, int nargs, ...) > > > { > > > - struct ucall uc = { > > > - .cmd = cmd, > > > - }; > > > + struct ucall uc = {}; > > > va_list va; > > > int i; > > > > > > + WRITE_ONCE(uc.cmd, cmd); > > > nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS; > > > > > > va_start(va, nargs); > > > for (i = 0; i < nargs; ++i) > > > - uc.args[i] = va_arg(va, uint64_t); > > > + WRITE_ONCE(uc.args[i], va_arg(va, uint64_t)); > > > va_end(va); > > > > > > - *ucall_exit_mmio_addr = (vm_vaddr_t)&uc; > > > + WRITE_ONCE(*ucall_exit_mmio_addr, (vm_vaddr_t)&uc); > > > } > > Am I misreading things again? > That function looks like it writes the address of an on-stack > item into global data. The write to the address that the global points at causes a switch from guest to host context. The guest's stack remains intact while executing host code and the host can access the uc stack variable directly by its address. Take a look at lib/aarch64/ucall.c to see all the details. Thanks, drew