Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1530339pxb; Sun, 12 Sep 2021 22:56:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5UHjPz46JUvxZqrSQT3nd1F9m8IITKN9teb/VpRdoi2VS3J1HzGLzmmB1wkd/ny5i+0tu X-Received: by 2002:a50:ee82:: with SMTP id f2mr11365415edr.15.1631512613426; Sun, 12 Sep 2021 22:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631512613; cv=none; d=google.com; s=arc-20160816; b=UzpJFDkmas3d8XR36/p0fWWygVZ24shRK/5X2f9IMzAdZusq+jTIz/fimI+A/lUh+c 2hd9yUBh2d5lvkv4kPExxIocQvJM4fCDNsRLrtB1CT9+B7U4S7FGSDKuavS92/dt5ONp M1QFrVPPzvy/4TmKUKjDOtIKXCENbCWm3/NQ/jpJKfA/wwXnNBXpIa7ILaEqEh1nQXmI c6wiEMhHcEn1Kc5FnMqgs6OrXLcTEWC6FRQaruXDx5oTOUQqjLsiEKSQey++3STEkSow GfxjeqZ9ttdLClzxZIYtL2e02926iMWtJ+JBqCYhVtX3oClsXIkaux6vUlnaXJ5ygF/U 4ujA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JEx0s8/aKXt0XKMD6l6fHz2qIfkUzAG/Tkrbj3E9G4I=; b=d9z5WR0o0svftgVdzJHnkt7Rp5OxSoTT8RSwSabwOevT7H9Ze3+R3Fuo4UWzbIzGGe 8U1ZEa5PBvKayfYm+rbQQPDn7zfJfSKYc9NQ1NnpDxyg60aglUVKw7+1PeWs23mn2U9g 69XGbZnlOf4iVhnBjeAM/5dP7QYDKN2UnbJfqnFAT6cp8sOjOcbA+C0ohT2g5w9GfHv4 90Qn2f7hpuR/fWVC6IiMVcA6nE0IiGSpRE6g9NdlAUoeEP3oVcJWnD5eW+pFP3QxKxkr i3rRolgetDyrvfcq3sDxhROh4BufRkvOENDJFIogiun9JpkvLkMj4pXlVt88Mo0eHZ3M JCjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DH86yepj; 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 d12si6508329edx.464.2021.09.12.22.56.30; Sun, 12 Sep 2021 22:56:53 -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=DH86yepj; 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 S237201AbhIMFz5 (ORCPT + 99 others); Mon, 13 Sep 2021 01:55:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44255 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237183AbhIMFz4 (ORCPT ); Mon, 13 Sep 2021 01:55:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631512481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JEx0s8/aKXt0XKMD6l6fHz2qIfkUzAG/Tkrbj3E9G4I=; b=DH86yepjZNfnfqn9RkkAaI5B0WKZyvLxg+/AOt5/zSdq8GJPYn4RgFMmGaC0u3xwPowlWU wRfabEbTbZD/2mm3InitwdQX0bw868mKBmG4Au65761V9ShnEU/EaLF2vbMcnM2il9RaKC huxG8joPEwOJJLLSUPEWAWnoVCYpE0Y= 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-301-Mr5BwugGMlCO3EwREBRr5A-1; Mon, 13 Sep 2021 01:54:37 -0400 X-MC-Unique: Mr5BwugGMlCO3EwREBRr5A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30A808145FF; Mon, 13 Sep 2021 05:54:36 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-146.pek2.redhat.com [10.72.13.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 615D15F706; Mon, 13 Sep 2021 05:54:33 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, f.hetzelt@tu-berlin.de, david.kaplan@amd.com, konrad.wilk@oracle.com, Amit Shah Subject: [PATCH 3/9] virtio-console: switch to use .validate() Date: Mon, 13 Sep 2021 13:53:47 +0800 Message-Id: <20210913055353.35219-4-jasowang@redhat.com> In-Reply-To: <20210913055353.35219-1-jasowang@redhat.com> References: <20210913055353.35219-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch switches to use validate() to filter out the features that is not supported by the rproc. Cc: Amit Shah Signed-off-by: Jason Wang --- drivers/char/virtio_console.c | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 7eaf303a7a86..daeed31df622 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -1172,9 +1172,7 @@ static void resize_console(struct port *port) vdev = port->portdev->vdev; - /* Don't test F_SIZE at all if we're rproc: not a valid feature! */ - if (!is_rproc_serial(vdev) && - virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) + if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) hvc_resize(port->cons.hvc, port->cons.ws); } @@ -1981,6 +1979,29 @@ static void virtcons_remove(struct virtio_device *vdev) kfree(portdev); } +static int virtcons_validate(struct virtio_device *vdev) +{ + if (is_rproc_serial(vdev)) { + /* Don't test F_SIZE at all if we're rproc: not a + * valid feature! */ + __virtio_clear_bit(vdev, VIRTIO_CONSOLE_F_SIZE); + /* Don't test MULTIPORT at all if we're rproc: not a + * valid feature! */ + __virtio_clear_bit(vdev, VIRTIO_CONSOLE_F_MULTIPORT); + } + + /* We only need a config space if features are offered */ + if (!vdev->config->get && + (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE) + || virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT))) { + dev_err(&vdev->dev, "%s failure: config access disabled\n", + __func__); + return -EINVAL; + } + + return 0; +} + /* * Once we're further in boot, we get probed like any other virtio * device. @@ -1996,15 +2017,6 @@ static int virtcons_probe(struct virtio_device *vdev) bool multiport; bool early = early_put_chars != NULL; - /* We only need a config space if features are offered */ - if (!vdev->config->get && - (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE) - || virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT))) { - dev_err(&vdev->dev, "%s failure: config access disabled\n", - __func__); - return -EINVAL; - } - /* Ensure to read early_put_chars now */ barrier(); @@ -2031,9 +2043,7 @@ static int virtcons_probe(struct virtio_device *vdev) multiport = false; portdev->max_nr_ports = 1; - /* Don't test MULTIPORT at all if we're rproc: not a valid feature! */ - if (!is_rproc_serial(vdev) && - virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT, + if (virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT, struct virtio_console_config, max_nr_ports, &portdev->max_nr_ports) == 0) { multiport = true; @@ -2210,6 +2220,7 @@ static struct virtio_driver virtio_console = { .driver.name = KBUILD_MODNAME, .driver.owner = THIS_MODULE, .id_table = id_table, + .validate = virtcons_validate, .probe = virtcons_probe, .remove = virtcons_remove, .config_changed = config_intr, -- 2.25.1