Received: by 10.223.185.116 with SMTP id b49csp386888wrg; Thu, 22 Feb 2018 23:54:48 -0800 (PST) X-Google-Smtp-Source: AH8x225UwlT53o31Di5FcwKA0fbvhQe9R/Nn8JCc42jgxrOi+8uqurxIlTJ1Ttokwz0QvLqNvXKn X-Received: by 10.98.171.24 with SMTP id p24mr876120pff.71.1519372488487; Thu, 22 Feb 2018 23:54:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519372488; cv=none; d=google.com; s=arc-20160816; b=xVvaeP4i/W4AkYM9w4OB0Iq/ww3YFmLvGTsYaC5qJKuYEq6H4a8fzPIbI1832RwMQp RyA47uy87kmOUQEVSnpxOfezlpZ/rmAoTalVShOaOEG++DR+FXGE5bKcz33JBQyoiSXK XxibTDEtDHwKGcyiZd7tNDlDjfcn3TfdewkJxw47PaWhHYKyHcnuvKsPf64fP5WaB0FS 3SDQoRg/4lQAZ+3bO8Kky0twFHv1/k5u6F5XyUQikbg+1uza3VHOVB0nUvzTtJXD5FYd 1uzBo3lXvBQjtUisxkJ15Dx9bvjL6jJqhnERy78WkK/iEiUUJLgxMDod/qeaWV5LEPWm qExA== 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 :arc-authentication-results; bh=/QaLQJEgFTy9C0iCh9RFEJef4d1sUemLzf7Moq2O3Io=; b=0aGL8UxYb/RKcJhnO35T+E2j0Of2omyxhPJm0b7dzAjSoV9fCzL63bMjUvgBU2V4fF J6DbjL2RO96U/9WRn5qa3gF4a20ILyXEZ+kYV5V8wgCNvGQH5cjzfPLy0FfLCGO4Nhmf JsrEWzhRKU2hphxiXIAn+BN2Ah9AeTxmMXGmj7gE8auFEd/4RWA2ilujalmMztaY2aS8 J8ImQuNVa5gCYmkOHXEffTz3pJ1Bd1LyawS3pROT9PvtgMI/r6NciJfmUqpd/4TquSDU QbDI+RwJIgT7sffW5kka8QsJO/161nhn/abbHOKBNZ7JPAnVJE76rp+hjO0uf1/pzyCC 1K0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bOGmpXfa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67si1193408pgy.24.2018.02.22.23.54.34; Thu, 22 Feb 2018 23:54:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bOGmpXfa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751329AbeBWHxz (ORCPT + 99 others); Fri, 23 Feb 2018 02:53:55 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36500 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750798AbeBWHxx (ORCPT ); Fri, 23 Feb 2018 02:53:53 -0500 Received: by mail-lf0-f68.google.com with SMTP id t79so11107164lfe.3 for ; Thu, 22 Feb 2018 23:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=/QaLQJEgFTy9C0iCh9RFEJef4d1sUemLzf7Moq2O3Io=; b=bOGmpXfaaq71K2bl42EpV067hdUd/y50IcT+rYoYuTqIdUyytb8ZdM8+uzahbc1sFn OI1hN/UlQzLGYvOF4qAVhxqieyg8S5BUAPCK3p8ANMKQgNfYCe9J9TLbZtUBMPKceJD/ 5mTZPo5JsyLKFog5y9XFA7eBlQvqaNniEOVk6cv06195G2/3bClv0UL1aatSs16+naHq HRz844JfImEFkKXnFVpnxi0FUX7+KQhEMsvZjDkfCAEw7ZckYSPYMB9H5fAiztFixzts lO4xVy0t0UeVKyiAvOpjU77Mala2CDZZ4DzhYDBzThJ6VWXVs6wm3GwNq4hOinmZxcdk VKoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=/QaLQJEgFTy9C0iCh9RFEJef4d1sUemLzf7Moq2O3Io=; b=A34rcG2wQKfSJPsM3ty2E7aM3p2n32S7dJeH2AP0WHq5T8pRj5fiObwwjYqUOp/xEo ahx0mrDHdAOcvggUaP0q9UJbmhXaO0WXqVyiNMjwQVygMYRykMApDvDY+JmfC9mg6uYU phYAaBYBtezBtflbbv7mHESv7Kc/9pEhybs/WLDWhdYq+7cek9jQRYUOqrE0HA+CnzGu DBAkvZf7RvywjlvyUd7VJn+YMtV8kkuvlw4FbQQknUoV1KXCK+k6p4xxdfHKmsx0GgH7 t1sFTdByu4v4FaA+BPSHKHSihdTX17hvmY/HEQOd5fyw2lXgZSqQdmzIyN2tl7lvJB3K wXfg== X-Gm-Message-State: APf1xPBXys7/wf3qqrvIyk1MdZkFJBKzMsIhnueVWvePNz7DcwQHpQA7 dIthf5gqzHRynzhy1cKiAXE= X-Received: by 10.25.40.212 with SMTP id o203mr620718lfo.103.1519372432330; Thu, 22 Feb 2018 23:53:52 -0800 (PST) Received: from [10.17.182.9] (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id v83sm361200lje.53.2018.02.22.23.53.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 23:53:51 -0800 (PST) Subject: Re: [PATCH 5/9] drm/xen-front: Implement handling of shared display buffers To: Boris Ostrovsky , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, daniel.vetter@intel.com, seanpaul@chromium.org, gustavo@padovan.org, jgross@suse.com, konrad.wilk@oracle.com Cc: Oleksandr Andrushchenko References: <1519200222-20623-1-git-send-email-andr2000@gmail.com> <1519200222-20623-6-git-send-email-andr2000@gmail.com> <11ce6c96-1739-435c-4b6f-c9f5d02a2905@oracle.com> From: Oleksandr Andrushchenko Message-ID: Date: Fri, 23 Feb 2018 09:53:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <11ce6c96-1739-435c-4b6f-c9f5d02a2905@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/23/2018 02:25 AM, Boris Ostrovsky wrote: > On 02/21/2018 03:03 AM, Oleksandr Andrushchenko wrote: >> >> static int __init xen_drv_init(void) >> { >> + /* At the moment we only support case with XEN_PAGE_SIZE == PAGE_SIZE */ >> + BUILD_BUG_ON(XEN_PAGE_SIZE != PAGE_SIZE); > > Why BUILD_BUG_ON? This should simply not load if page sizes are different. > > This is a compile time check, so if kernel/Xen is configured to use page size combination which is not supported by the driver it will fail during compilation. This seems correct to me, because you shouldn't even try to load the driver which cannot handle different page sizes to not make any harm. > > > >> + ret = gnttab_map_refs(map_ops, NULL, buf->pages, buf->num_pages); >> + BUG_ON(ret); > > We should try not to BUG*(). There are a few in this patch (and possibly > others) that I think can be avoided. > I will rework BUG_* for map/unmap code to handle errors, but will still leave     /* either pages or sgt, not both */     BUG_ON(cfg->pages && cfg->sgt); which is a real driver bug and must not happen > > > >> + >> +static int alloc_storage(struct xen_drm_front_shbuf *buf) >> +{ >> + if (buf->sgt) { >> + buf->pages = kvmalloc_array(buf->num_pages, >> + sizeof(struct page *), GFP_KERNEL); >> + if (!buf->pages) >> + return -ENOMEM; >> + >> + if (drm_prime_sg_to_page_addr_arrays(buf->sgt, buf->pages, >> + NULL, buf->num_pages) < 0) >> + return -EINVAL; >> + } >> + >> + buf->grefs = kcalloc(buf->num_grefs, sizeof(*buf->grefs), GFP_KERNEL); >> + if (!buf->grefs) >> + return -ENOMEM; >> + >> + buf->directory = kcalloc(get_num_pages_dir(buf), PAGE_SIZE, GFP_KERNEL); >> + if (!buf->directory) >> + return -ENOMEM; > You need to clean up on errors. this is called in xen_drm_front_shbuf_alloc and is properly cleaned on failure, e.g.:     ret = alloc_storage(buf);     if (ret)         goto fail; [...] fail:     xen_drm_front_shbuf_free(buf); > -boris > >> + >> + return 0; >> +}