Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp701986pxb; Thu, 2 Sep 2021 13:02:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH9kW9cwyf6qIhdIyL/jRst6zSYZBBy7wuYtgeemK0/hpjV5YQh2W8QLqGDNSfOfvtpXBt X-Received: by 2002:a17:907:7752:: with SMTP id kx18mr5435000ejc.276.1630612924675; Thu, 02 Sep 2021 13:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630612924; cv=none; d=google.com; s=arc-20160816; b=EovKjL46/ZUEy6NsvAO9aq2tQUqbB7ztl57vBsVEvzdjD2VKaS4YzuuDJvNsiYH7Fj e1dESPZ8S4ZytppcHIQGZ757p1MAmMCiGRViIczywo9DHbMTNsxh+oJIC9HnRCteFQCM HyM1WtMF1vyDWLSjCL8PCi0TLpMXrZN1GgfMDvS/k6MG3Uv6E7HyqS5lm5YADGZoPzMT fq6D4+gjNbJ8nJg8cA3AsXiY3JBELBNzwbKTisSZ0S8qay8+xCmLicYCEi/ZRjEtX6/q 1wwyNN2zpYQz+Z2DSC327vEpZERS+5+h0tyxfWdQD5dG5JsYWjWtPyyMyoN2M8JbUH+q YmlA== 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=6tJf5xIvKDCnRwuvzEhUuuc4fd9eQkxx1PjNi93Vu3s=; b=jOfEl72Dp+wuOsa/AzIL0USsdGGCrXxX/QAzaf8pwCbCj1Z2ojLrNakfgfHENcDD9n ffhQUVqu4eoCjuMcUcb4Jn5nkTHJ9sfRWCae2/tc62mZVT4fgltAdbqHSxPnmtf7sieO PZhCjB23MoUPAnKjf2Yr0kq9nViPYfO6BNbph99UD0cYwVH6SqdkLQyNPYX31TmdSH7q ON8xJVw9RFLfDl6FwIViTfC02LmNob0WdwyLmmb9rgCX8OgSzNbqvT7yPmaPbKZ2BePW x4VbV94AtEJniqjk69uqIS+kLlyuHWhjhJ3O224MFNcsUyWqoyEyCZulyfaY68td1VAI DS5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SnzWriVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si3257120ejq.154.2021.09.02.13.01.22; Thu, 02 Sep 2021 13:02:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SnzWriVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1344995AbhIBNWV (ORCPT + 99 others); Thu, 2 Sep 2021 09:22:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26983 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344959AbhIBNWR (ORCPT ); Thu, 2 Sep 2021 09:22:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630588878; 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=6tJf5xIvKDCnRwuvzEhUuuc4fd9eQkxx1PjNi93Vu3s=; b=SnzWriVvL1J/4ZPJ06qeAlQl33FEpWh9jdCEPiw9zTq8pOJ7Y6W2+DQZAr/Uw+0tVj6GPH m+Ll5hv+zguwNMRcQ7NjAK+z6iDs9LuIks9uLmWlcbN366y8VKl5zTZBgR9AgzcUnfGTcf 7k62Rd/2GOiRK8t40gG/ZtjYAWL30UM= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-600-HnkKsZhAOgmFocP9Dur1_w-1; Thu, 02 Sep 2021 09:21:17 -0400 X-MC-Unique: HnkKsZhAOgmFocP9Dur1_w-1 Received: by mail-qv1-f72.google.com with SMTP id ib9-20020a0562141c8900b003671c3a1243so1479135qvb.21 for ; Thu, 02 Sep 2021 06:21:17 -0700 (PDT) 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=6tJf5xIvKDCnRwuvzEhUuuc4fd9eQkxx1PjNi93Vu3s=; b=UaBwWEKIwM14hAn4jkm0IQ8iM2by8lBzm1W6zPzZVhLuT5taH7tVXFWU66cCZXPEQI OMv3t7COokBoTY5mFtGQAWdI7ccE1DO8yQaX1sctCYELkrlgUSHW88uteA0IjYyDbiXX LYuPvnHdxYxP/vx4dbCL2b8Y6zJFgKPt3cIz9SKv8KQDZ0m0pyO3kncRsNavWBY0e0SD WXhAtZUz/WKJkiFJXTQaYmxAPwEJMEQGeAbqb/VhSDXqxwDnhlrgPVnpa5zu3MVS9JN/ XQ3UtJSvfOZuwP3hZFE2+gHyaDeuYo2X7uHgoV47eiI6RJ2yxbkXG+Jg8B2eS4e2fDEL ZOvQ== X-Gm-Message-State: AOAM533OzdppUKqcO/78ShZfzup3jYtRactHPHDEJv/ymqhzBqeLEM31 DWd6mg/8oTvOr26YCLq4DaWhRDja/KC49BHO3JQxJZbLNC/dFJi9AqN32GsPj2q6aY8zG75DwWw tbqsHTABhw3n/swz/3WTUi+8M X-Received: by 2002:ad4:562c:: with SMTP id cb12mr1587969qvb.6.1630588877099; Thu, 02 Sep 2021 06:21:17 -0700 (PDT) X-Received: by 2002:ad4:562c:: with SMTP id cb12mr1587947qvb.6.1630588876898; Thu, 02 Sep 2021 06:21:16 -0700 (PDT) Received: from gator (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id g8sm1319814qkm.25.2021.09.02.06.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 06:21:16 -0700 (PDT) Date: Thu, 2 Sep 2021 15:21:12 +0200 From: Andrew Jones To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , kvm@vger.kernel.org, Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 01/12] KVM: arm64: selftests: Add MMIO readl/writel support Message-ID: <20210902132112.yyz7iiqims3nlmmi@gator> References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-2-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210901211412.4171835-2-rananta@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 01, 2021 at 09:14:01PM +0000, Raghavendra Rao Ananta wrote: > Define the readl() and writel() functions for the guests to > access (4-byte) the MMIO region. > > The routines, and their dependents, are inspired from the kernel's > arch/arm64/include/asm/io.h and arch/arm64/include/asm/barrier.h. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../selftests/kvm/include/aarch64/processor.h | 45 ++++++++++++++++++- > 1 file changed, 44 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > index c0273aefa63d..3cbaf5c1e26b 100644 > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > @@ -130,6 +130,49 @@ void vm_install_sync_handler(struct kvm_vm *vm, > val; \ > }) > > -#define isb() asm volatile("isb" : : : "memory") > +#define isb() asm volatile("isb" : : : "memory") > +#define dsb(opt) asm volatile("dsb " #opt : : : "memory") > +#define dmb(opt) asm volatile("dmb " #opt : : : "memory") > + > +#define dma_wmb() dmb(oshst) > +#define __iowmb() dma_wmb() > + > +#define dma_rmb() dmb(oshld) > + > +#define __iormb(v) \ > +({ \ > + unsigned long tmp; \ > + \ > + dma_rmb(); \ > + \ > + /* \ > + * Courtesy of arch/arm64/include/asm/io.h: \ > + * Create a dummy control dependency from the IO read to any \ > + * later instructions. This ensures that a subsequent call \ > + * to udelay() will be ordered due to the ISB in __delay(). \ We don't have udelay or __delay yet, but I assume they're coming soon. > + */ \ > + asm volatile("eor %0, %1, %1\n" \ > + "cbnz %0, ." \ > + : "=r" (tmp) : "r" ((unsigned long)(v)) \ > + : "memory"); \ > +}) > + > +static __always_inline void __raw_writel(u32 val, volatile void *addr) > +{ > + asm volatile("str %w0, [%1]" : : "rZ" (val), "r" (addr)); > +} > + > +static __always_inline u32 __raw_readl(const volatile void *addr) > +{ > + u32 val; > + asm volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr)); > + return val; > +} > + > +#define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) > +#define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) Might want to explicitly include linux/types.h for these __force symbols. > + > +#define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c));}) > +#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(__v); __v; }) > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > -- > 2.33.0.153.gba50c8fa24-goog Reviewed-by: Andrew Jones Thanks, drew > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm >