From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 707A0C433B4 for ; Fri, 14 May 2021 00:57:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21FB561206 for ; Fri, 14 May 2021 00:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21FB561206 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.127119.238859 (Exim 4.92) (envelope-from ) id 1lhM99-0005nO-AR; Fri, 14 May 2021 00:57:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 127119.238859; Fri, 14 May 2021 00:57:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lhM99-0005nD-4l; Fri, 14 May 2021 00:57:43 +0000 Received: by outflank-mailman (input) for mailman id 127119; Fri, 14 May 2021 00:57:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lhM97-0004or-7a for xen-devel@lists.xenproject.org; Fri, 14 May 2021 00:57:41 +0000 Received: from mail-io1-xd2a.google.com (unknown [2607:f8b0:4864:20::d2a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 44082472-4656-4a6d-84d0-b4f193f1ea8e; Fri, 14 May 2021 00:57:31 +0000 (UTC) Received: by mail-io1-xd2a.google.com with SMTP id d11so6153836iod.5 for ; Thu, 13 May 2021 17:57:31 -0700 (PDT) Received: from localhost.localdomain (142-79-211-230.starry-inc.net. [142.79.211.230]) by smtp.gmail.com with ESMTPSA id g25sm1981538ion.32.2021.05.13.17.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 17:57:31 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 44082472-4656-4a6d-84d0-b4f193f1ea8e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kaolo11x7BDn/0QfbTzKyesjjtUEBXBeIP8y1OlvuS8=; b=oNgcz//ZDfFesKvkG1DPiB9mV5Cjp3q09B7rZg/T1l5DnxEicJF0uHcIatOkszgULL SQEJkOvXso5TLe2DSdp1mnCW64dlGG6ReyWh0c7IIHMw9cwQsc362Qp27R2rjjO8CVQd Hsw6El7hP5PO+qzVt53ggMKbyvifV+phwY4TkxOVrtqS6hgLNDvZV6mBSbUARwiLfufR Ly6yjfKaiELXc2e4+vGzFYHJ0ZIMTafqZLtowv+yMlm4zsWPw3g2DEpcIKeDfUdmlAhM CdJOXn8FA9S3rpcCWGZkKyU4k5ld6wYJ5P997dkD5hYRHf17+oUiV7WuTWVcVh/IGXQM RjMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kaolo11x7BDn/0QfbTzKyesjjtUEBXBeIP8y1OlvuS8=; b=pe2bZeeiyWKawuIFSeIHAhu/NIyhFPeWGdoF4B/vDbL6TyYiCzyC88iWqhc45koHAa 6Km9gyKoPnEcu2jYOLDdlZduvi3kBGH8xyUjLzkA29LlFwdiFZl3AUxPHCUQSK6pTnG2 nd/lQEddadNF+Le/BM9VAzF/+2nSfL4Zd+mjBOdl8HAiZ8rJ7wlddMT6moFlK1hxJef2 HzNGvFxq8IhGjo1DaRKGw+WDp7H7LsHLD6b1svshqDVhjn8NIuxLiuFHHHLXO3lUAwgE HyVjkVjgVxiYVjZBx2G4mfDaGCsC4NHD6G7V0bEH37Aks/5/4m+Zq56CHeU9wwa7zELf y9HA== X-Gm-Message-State: AOAM531IYC2JZBZg/75ciyR6SSa+YUAHkMxCycwzJXG2/fPDMjtVc5Mq PhlLz3qvEDqUMJHH+RJ7/IY= X-Google-Smtp-Source: ABdhPJygkbUw3fnDxhQdUp2/4URvzqUJF2PZVWTCLi/wLAoCtayuWSrLwm2fsyOwJJpdijs/Hs4iAg== X-Received: by 2002:a05:6638:3013:: with SMTP id r19mr41336649jak.36.1620953851491; Thu, 13 May 2021 17:57:31 -0700 (PDT) From: Connor Davis To: Greg Kroah-Hartman , Boris Ostrovsky , Juergen Gross , Stefano Stabellini Cc: Connor Davis , Douglas Anderson , "Eric W. Biederman" , Chunfeng Yun , Petr Mladek , Sumit Garg , Lee Jones , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH v2 3/4] usb: dbgp: Fix return values for reset prep and startup Date: Thu, 13 May 2021 18:56:50 -0600 Message-Id: <0010a6165f3560f16123a142d297276e7d6c2087.1620952511.git.connojdavis@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Callers of dbgp_reset_prep treat a 0 return value as "stop using the debug port", which means they don't make any subsequent calls to dbgp_reset_prep or dbgp_external_startup. To ensure the callers' interpretation is correct, first return -EPERM from xen_dbgp_op if !xen_initial_domain(). This ensures that both xen_dbgp_reset_prep and xen_dbgp_external_startup return 0 iff the PHYSDEVOP_DBGP_RESET_{PREPARE,DONE} hypercalls succeed. Also update xen_dbgp_reset_prep and xen_dbgp_external_startup to return -EPERM when !CONFIG_XEN_DOM0 for consistency. Next, return nonzero from dbgp_reset_prep if xen_dbgp_reset_prep returns 0. The nonzero value ensures that callers of dbgp_reset_prep will subsequently call dbgp_external_startup when it is safe to do so. Also invert the return values from dbgp_external_startup for consistency with dbgp_reset_prep (this inversion has no functional change since no callers actually check the value). Signed-off-by: Connor Davis --- drivers/usb/early/ehci-dbgp.c | 9 ++++++--- drivers/xen/dbgp.c | 2 +- include/linux/usb/ehci-dbgp.h | 14 +++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c index 45b42d8f6453..ff993d330c01 100644 --- a/drivers/usb/early/ehci-dbgp.c +++ b/drivers/usb/early/ehci-dbgp.c @@ -970,8 +970,8 @@ int dbgp_reset_prep(struct usb_hcd *hcd) int ret = xen_dbgp_reset_prep(hcd); u32 ctrl; - if (ret) - return ret; + if (!ret) + return 1; dbgp_not_safe = 1; if (!ehci_debug) @@ -995,7 +995,10 @@ EXPORT_SYMBOL_GPL(dbgp_reset_prep); int dbgp_external_startup(struct usb_hcd *hcd) { - return xen_dbgp_external_startup(hcd) ?: _dbgp_external_startup(); + if (!xen_dbgp_external_startup(hcd)) + return 1; + + return !_dbgp_external_startup(); } EXPORT_SYMBOL_GPL(dbgp_external_startup); #endif /* USB */ diff --git a/drivers/xen/dbgp.c b/drivers/xen/dbgp.c index fef32dd1a5dc..d54f98380e6f 100644 --- a/drivers/xen/dbgp.c +++ b/drivers/xen/dbgp.c @@ -15,7 +15,7 @@ static int xen_dbgp_op(struct usb_hcd *hcd, int op) struct physdev_dbgp_op dbgp; if (!xen_initial_domain()) - return 0; + return -EPERM; dbgp.op = op; diff --git a/include/linux/usb/ehci-dbgp.h b/include/linux/usb/ehci-dbgp.h index 62ab3805172d..c0e98557efc0 100644 --- a/include/linux/usb/ehci-dbgp.h +++ b/include/linux/usb/ehci-dbgp.h @@ -56,28 +56,32 @@ extern int xen_dbgp_external_startup(struct usb_hcd *); #else static inline int xen_dbgp_reset_prep(struct usb_hcd *hcd) { - return 1; /* Shouldn't this be 0? */ + return -EPERM; } static inline int xen_dbgp_external_startup(struct usb_hcd *hcd) { - return -1; + return -EPERM; } #endif #ifdef CONFIG_EARLY_PRINTK_DBGP -/* Call backs from ehci host driver to ehci debug driver */ +/* + * Call backs from ehci host driver to ehci debug driver. + * Returns 0 if the debug port should stopped being used, + * nonzero otherwise. + */ extern int dbgp_external_startup(struct usb_hcd *); extern int dbgp_reset_prep(struct usb_hcd *); #else static inline int dbgp_reset_prep(struct usb_hcd *hcd) { - return xen_dbgp_reset_prep(hcd); + return !xen_dbgp_reset_prep(hcd); } static inline int dbgp_external_startup(struct usb_hcd *hcd) { - return xen_dbgp_external_startup(hcd); + return !xen_dbgp_external_startup(hcd); } #endif -- 2.31.1