From patchwork Fri May 14 00:56:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Davis X-Patchwork-Id: 439288 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=ham 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 25D36C43461 for ; Fri, 14 May 2021 00:57:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0411D61206 for ; Fri, 14 May 2021 00:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbhENA6p (ORCPT ); Thu, 13 May 2021 20:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbhENA6n (ORCPT ); Thu, 13 May 2021 20:58:43 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE611C061574; Thu, 13 May 2021 17:57:31 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id i7so19221319ioa.12; Thu, 13 May 2021 17:57:31 -0700 (PDT) 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=nSDW4SN4x0/yANZTctPn5DyEWNp64CZBCcciNkVf7W8KhnJHsgdMYjCNZQ7qCOl5+J 04CGOVfUxfamGukrBj5y83W494U+PHezfDFQfOCTnfxsLhc+0noRIpaclDFiBND3iuXy EtgxpFYw4mr3vSzTw8ARIxlkxE+TC656F/wWL4TtozzOH0WTbiOPmNgPrc5ysVV/Ue+P YRuLGFyyrpqvdadxbixnZ3orrhrmW6L9smswShwdLusL6Cu7KXyXIynE8HsRX1mCf7UJ Q98FMA28uUR6OsUD30M/E6qo53uh3htakh29reUxvfWXd5wq7pIvPIzb4uJx1GbfZZKi 2olA== X-Gm-Message-State: AOAM533i0H+Mdc0chDQA0YWILBiPPEhRd6LC04yGFjOf+MSZt2HlV4Ak PF1NYnI8LauUEXxhaALF/Z4= 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) 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) 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 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Reviewed-by: Boris Ostrovsky --- 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