From patchwork Tue Apr 30 23:55:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 163165 Delivered-To: patches@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp3882784ill; Tue, 30 Apr 2019 16:56:02 -0700 (PDT) X-Received: by 2002:a63:b53:: with SMTP id a19mr26501859pgl.216.1556668562809; Tue, 30 Apr 2019 16:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556668562; cv=none; d=google.com; s=arc-20160816; b=NGUjvEblMx1AynOu0XTjnBt5gjGLHrdg1PyzbAXMR6VNLhMP5VVkExC1L+Fpbipt8q 6JYgTxDoVxoQstid/B7qBGh5+rjSkd/wVRjv4nt8hdwNEoCv6b7FLmuKauSfkWhzmlv/ w8FbncMndNMN1lIe/H/kJG7hRpaJsu7IzW00JZjHl1sDpXVo7HtnjQH9n+cJBm49GdX6 b3/UY0Pu2yXQMieSLZwTsZPSdH2TaqEfYrL608FLlriyXTLChmev8E7fSyuuHCVpWmqu ayrfF4V6dUvNElzV2pUnWfW0pPYQEdZN7VVy/bbYYTKTnST28REqbfUfgBo++Xd7PBhm u0Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=9GaBhigPlBJD0Wvjf14pqWUfdunV4V14rZgzng8Rqag=; b=xNcf8+rWRZD2zI6Sc1v8d8e9fZ3Qc/sPyV1cr6hNu9PWDnYkJVK5dxklcn/485NDMc rWK8QMUYMacXqM+T4fisgZrfDS5FxQFxqLRyaAFO2QomE+O/0BAOoEy1cYk4vtSMi8jX FUbgH343+HZR+EyJu4u70X8sglgzogDCOG6QEmP+BEWoNlFSoZzgc/Gvov1Mti64ov/V fAMGCpLS/wATv2RXDSYtKuvQdIHsxRgvY+dO8sxKTrbkJtuRaWErChcNSfw+BXUT/N4W j4qcp5KQNf44xcnGZb/32w9SNP6LJeIhGHOK85P2Q/BCiS6aIm9Wlnoy+nI7ebrKqAB3 5LSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FcAg81Ge; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d9sor2600416pls.64.2019.04.30.16.56.02 for (Google Transport Security); Tue, 30 Apr 2019 16:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FcAg81Ge; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=9GaBhigPlBJD0Wvjf14pqWUfdunV4V14rZgzng8Rqag=; b=FcAg81GevTXRIFf6TIu8NCc9z20UW+AHbRJ8cAPEnObDaLFaKIXSNWXFlwR+J7Bg3q 6VOkopMrnW5txNX50ZCqTtYRRtosQXOMh51UAy7+5viStfm+uV8Qp0OwP64ss0zW4iLG GYmtxnpDApXkTp1cYtlTJ70l+ntEtfWWAbnlUpgUzYvZL7MC1EBG9Ym4e6aGOTfO7wAF bfdeQiC0qOF7NYVWWS/nfIRXeK0fxgxGYzWHsqHpT/1QkLNUedLGhas6qlPPA+olhO5c CG2J6b1A55NLs8tAISelNG+frsk3KBPzruxWInPfcLow1h8DSs7qLauxc/RCmevP02dN 09hA== 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; bh=9GaBhigPlBJD0Wvjf14pqWUfdunV4V14rZgzng8Rqag=; b=F4LHudts1lA75kvFvilW88MBO+/o4yWzKN0Mo5YThXXSLXsQdUg8iCa07v47bheqwr ugGn+lf7sOgg9yxFGFj3y8cLvzReghlBmDzvM14dRCdWN01pixrvHKzCKlrFddLkq+vw Y2984qhUrSIH3PgFYGYl5/fsiVJgdUM/bTewGYbE6UeCFDCQxBJqXJUU02haeV5qhbjz 3CIEzqh8gy0msoX7LFKX5KdDRmZxIeiBAtDbdPIBYA1H+rbwOKGgOLpIbsUQW+HhNPdr RvhKtJ93432beZTOnKcBLRylO3Igo9Jhz8RvOBC0ip85YSmct/s2uVUuuLz/dSf5ml8F JbUg== X-Gm-Message-State: APjAAAXbScJYNJe+o8ANbB5Q+iBcnKXc1RWOJKpZrT83vHxEtShj9gUI BPAuQzR9qw/u8tzzfw1xvgwt7xE7 X-Google-Smtp-Source: APXvYqw/OzuCORd/ZZhfLlhTflcShdnU5LciIDS2Wuz9pyhPvT1Emb9qncpQPviU3n69OWZi5eL62A== X-Received: by 2002:a17:902:b605:: with SMTP id b5mr34899098pls.206.1556668562248; Tue, 30 Apr 2019 16:56:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id h189sm80040578pfc.125.2019.04.30.16.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 16:56:01 -0700 (PDT) From: John Stultz To: Bjorn Andersson Cc: John Stultz , Amit Pundir , Sumit Semwal , dragonboard-aosp@lists.96boards.org Subject: [PATCH] qdl: Rework qdl_write to limit write sizes to out_maxpktsize Date: Tue, 30 Apr 2019 16:55:56 -0700 Message-Id: <20190430235556.2502-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 On a number of machines, qdl could cause crashes on the host system it ran on, due to swiotlb exaustion. This seems to be due to 1M buffers being used during the writes. In order to avoid this, rework qdl_write to break up the writes into out_maxpktsize chunks, and set max_payload_size to 64k With this patch, I no longer see host crashes when running qdl Cc: Bjorn Andersson Cc: Amit Pundir Cc: Sumit Semwal Cc: dragonboard-aosp@lists.96boards.org Signed-off-by: John Stultz --- firehose.c | 2 +- qdl.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/firehose.c b/firehose.c index ebe9c52..76dfb96 100644 --- a/firehose.c +++ b/firehose.c @@ -198,7 +198,7 @@ static int firehose_nop_parser(xmlNode *node) return !!xmlStrcmp(value, (xmlChar*)"ACK"); } -static size_t max_payload_size = 1048576; +static size_t max_payload_size = 65536; /** * firehose_configure_response_parser() - parse a configure response diff --git a/qdl.c b/qdl.c index 2b523d2..47debd9 100644 --- a/qdl.c +++ b/qdl.c @@ -354,20 +354,49 @@ int qdl_read(struct qdl_device *qdl, void *buf, size_t len, unsigned int timeout int qdl_write(struct qdl_device *qdl, const void *buf, size_t len, bool eot) { + + unsigned char *data = (unsigned char*) buf; struct usbdevfs_bulktransfer bulk = {}; - int ret; + unsigned count = 0; + size_t len_orig = len; int n; - bulk.ep = qdl->out_ep; - bulk.len = len; - bulk.data = (void *)buf; - bulk.timeout = 10000; + if(len == 0) { + bulk.ep = qdl->out_ep; + bulk.len = 0; + bulk.data = data; + bulk.timeout = 1000; - ret = ioctl(qdl->fd, USBDEVFS_BULK, &bulk); - if (ret < 0) - return ret; + n = ioctl(qdl->fd, USBDEVFS_BULK, &bulk); + if(n != 0) { + fprintf(stderr,"ERROR: n = %d, errno = %d (%s)\n", + n, errno, strerror(errno)); + return -1; + } + return 0; + } + + while(len > 0) { + int xfer; + xfer = (len > qdl->out_maxpktsize) ? qdl->out_maxpktsize : len; + + bulk.ep = qdl->out_ep; + bulk.len = xfer; + bulk.data = data; + bulk.timeout = 1000; + + n = ioctl(qdl->fd, USBDEVFS_BULK, &bulk); + if(n != xfer) { + fprintf(stderr, "ERROR: n = %d, errno = %d (%s)\n", + n, errno, strerror(errno)); + return -1; + } + count += xfer; + len -= xfer; + data += xfer; + } - if (eot && (len % qdl->out_maxpktsize) == 0) { + if (eot && (len_orig % qdl->out_maxpktsize) == 0) { bulk.ep = qdl->out_ep; bulk.len = 0; bulk.data = NULL; @@ -378,7 +407,7 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len, bool eot) return n; } - return ret; + return count; } static void print_usage(void)