Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp250719pxa; Tue, 4 Aug 2020 23:29:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBTBgQBp6SsIY+jJtFSRphaYqDZ61XAJIHh9ac95IDHR0B+D9QSaxtwN2gx51Me0OmtWDY X-Received: by 2002:a05:6402:16d1:: with SMTP id r17mr1357663edx.79.1596608981765; Tue, 04 Aug 2020 23:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596608981; cv=none; d=google.com; s=arc-20160816; b=sZ4gZw5uJZmb/g1OlZ9DH08tgtb5GFtZbAaUtJBC6ERhwJ3PK69QLf4ZeIEDWzIhLj QPlgvImmySi7owYeJ2DruhFRjiwXZxgDEb7EYPUT33n83oXLu8w5Wi/m8r8tgVIDA8E7 Z91TTYQCdnHVmNMM2TcJkPneoClVg836Uz3gGDrCZPSUvgBWWfayNKDKlq1q1V+VMhS6 nm3dFvHZri03E3KWQFjDbqHzFG2RvF/vixum/Ts3wo8FRHNY65jSz7HAdZZWlKN8XsAB 7yHW9+zD01ptBTQuLnhpJDr/E4PMFNb73lmKQBcm10O4gL3hD3zga3514/yy9WgR/y6M L/mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=j4EoEwZG+swIVHP0lP8YoiVbx/lrSzlRaGxj/pUTBqw=; b=K4UZfDYQan1uRDI1mxKcOr1bLOoW8xNpxWVUMK7aX7GCePlrO0twAYQBRRaD9Z1Ymv Lf2iiToFrlps2pE9CvyWbTqg3AFfO/foBi4CHeX1amtgmHoJO9DhZ+i5YjegVfCpumHf uw/KsbYgJ+DEzwX8AGT7C+iBnvdY8uDMLBlwDMIdkcBvB/G5i4DCZBqt+QD9KkdLZn/X nnSE9oG6F9uC8kgIuH+dUSc0Dtatir1l9tw0DdrXlDGLxpXKxmxTzWNRaX5j/eCtPy31 BtA2DlNgEyGfy8l9jUgugDs+DkR1DdOcC+W9s0D+DhfI5dm86TwrxQk+zlvwsl5Lx8lS uAKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DjPjawL6; 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 o18si651221ejg.391.2020.08.04.23.29.19; Tue, 04 Aug 2020 23:29:41 -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=DjPjawL6; 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 S1728003AbgHEG2g (ORCPT + 99 others); Wed, 5 Aug 2020 02:28:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54160 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727962AbgHEG2f (ORCPT ); Wed, 5 Aug 2020 02:28:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596608913; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j4EoEwZG+swIVHP0lP8YoiVbx/lrSzlRaGxj/pUTBqw=; b=DjPjawL6ilC5vBQ08ElH3Ygl4Kkbf+EWbdMarqHBnbbWSQHIlYbQJUdl4vV/KSkKN8+n/3 MOfNlWtgopi19fVJxQA/5bbyhLzScB4WND2hG4BAab1Zbx7ElHEAedkNT4bcidbKTLoOVL rVxSyYhebqkC+LaWNLbcDaAzb9pt+Us= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-Z6h-CcQlNsSmC0oA6Dl8uQ-1; Wed, 05 Aug 2020 02:28:31 -0400 X-MC-Unique: Z6h-CcQlNsSmC0oA6Dl8uQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D9F418FF662; Wed, 5 Aug 2020 06:28:30 +0000 (UTC) Received: from [10.72.12.225] (ovpn-12-225.pek2.redhat.com [10.72.12.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C97D8AC25; Wed, 5 Aug 2020 06:28:24 +0000 (UTC) Subject: Re: [PATCH v2 03/24] virtio: allow __virtioXX, __leXX in config space To: "Michael S. Tsirkin" , linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org References: <20200803205814.540410-1-mst@redhat.com> <20200803205814.540410-4-mst@redhat.com> From: Jason Wang Message-ID: Date: Wed, 5 Aug 2020 14:28:23 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200803205814.540410-4-mst@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/4 上午4:58, Michael S. Tsirkin wrote: > Currently all config space fields are of the type __uXX. > This confuses people and some drivers (notably vdpa) > access them using CPU endian-ness - which only > works well for legacy or LE platforms. > > Update virtio_cread/virtio_cwrite macros to allow __virtioXX > and __leXX field types. Follow-up patches will convert > config space to use these types. > > Signed-off-by: Michael S. Tsirkin > --- > include/linux/virtio_config.h | 50 +++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) > > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h > index 3b4eae5ac5e3..64da491936f7 100644 > --- a/include/linux/virtio_config.h > +++ b/include/linux/virtio_config.h > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > > struct irq_affinity; > @@ -287,12 +288,57 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) > return __cpu_to_virtio64(virtio_is_little_endian(vdev), val); > } > > +/* > + * Only the checker differentiates between __virtioXX and __uXX types. But we > + * try to share as much code as we can with the regular GCC build. > + */ > +#if !defined(CONFIG_CC_IS_GCC) && !defined(__CHECKER__) > + > +/* Not a checker - we can keep things simple */ > +#define __virtio_native_typeof(x) typeof(x) > + > +#else > + > +/* > + * We build this out of a couple of helper macros in a vain attempt to > + * help you keep your lunch down while reading it. > + */ > +#define __virtio_pick_value(x, type, then, otherwise) \ > + __builtin_choose_expr(__same_type(x, type), then, otherwise) > + > +#define __virtio_pick_type(x, type, then, otherwise) \ > + __virtio_pick_value(x, type, (then)0, otherwise) > + > +#define __virtio_pick_endian(x, x16, x32, x64, otherwise) \ > + __virtio_pick_type(x, x16, __u16, \ > + __virtio_pick_type(x, x32, __u32, \ > + __virtio_pick_type(x, x64, __u64, \ > + otherwise))) > + > +#define __virtio_native_typeof(x) typeof( \ > + __virtio_pick_type(x, __u8, __u8, \ > + __virtio_pick_endian(x, __virtio16, __virtio32, __virtio64, \ > + __virtio_pick_endian(x, __le16, __le32, __le64, \ > + __virtio_pick_endian(x, __u16, __u32, __u64, \ > + /* No other type allowed */ \ > + (void)0))))) > + > +#endif > + > +#define __virtio_native_type(structname, member) \ > + __virtio_native_typeof(((structname*)0)->member) > + > +#define __virtio_typecheck(structname, member, val) \ > + /* Must match the member's type, and be integer */ \ > + typecheck(__virtio_native_type(structname, member), (val)) > + > + > /* Config space accessors. */ > #define virtio_cread(vdev, structname, member, ptr) \ > do { \ > might_sleep(); \ > /* Must match the member's type, and be integer */ \ > - if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \ > + if (!__virtio_typecheck(structname, member, *(ptr))) \ > (*ptr) = 1; \ A silly question,  compare to using set()/get() directly, what's the value of the accessors macro here? Thanks > \ > switch (sizeof(*ptr)) { \ > @@ -322,7 +368,7 @@ static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val) > do { \ > might_sleep(); \ > /* Must match the member's type, and be integer */ \ > - if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \ > + if (!__virtio_typecheck(structname, member, *(ptr))) \ > BUG_ON((*ptr) == 1); \ > \ > switch (sizeof(*ptr)) { \